From 9b304748ad7632830753e3389cc014eec4f6a79d Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 16 Feb 2016 21:29:00 -0500 Subject: [PATCH 1/6] Work on terminology service --- .../ca/uhn/fhir/context/ModelScanner.java | 5 +- .../java/ca/uhn/fhir/util/ValidateUtil.java | 21 +++ .../ca/uhn/fhir/i18n/hapi-messages.properties | 4 +- .../ca/uhn/fhir/util/ValidateUtilTest.java | 50 ++++++ .../ca/uhn/fhir/jpa/config/BaseConfig.java | 8 + .../uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java | 7 +- .../fhir/jpa/dao/data/ITermCodeSystemDao.java | 34 ++++ .../dao/data/ITermCodeSystemVersionDao.java | 34 ++++ .../fhir/jpa/dao/data/ITermConceptDao.java | 35 ++++ .../data/ITermConceptParentChildLinkDao.java | 29 ++++ .../uhn/fhir/jpa/entity/TermCodeSystem.java | 42 +++-- .../jpa/entity/TermCodeSystemVersion.java | 88 ++++++++++ .../ca/uhn/fhir/jpa/entity/TermConcept.java | 122 ++++++++++++-- .../entity/TermConceptParentChildLink.java | 52 ++++-- .../ca/uhn/fhir/jpa/term/ITerminologySvc.java | 9 ++ .../uhn/fhir/jpa/term/TerminologySvcImpl.java | 130 +++++++++++++++ .../fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java | 24 +++ .../fhir/jpa/term/TerminologySvcImplTest.java | 151 ++++++++++++++++++ .../fhir/dstu3/model/fhirversion.properties | 3 + .../uhn/fhir/parser/JsonParserDstu3Test.java | 12 +- hapi-tinder-plugin/.classpath | 1 + 21 files changed, 820 insertions(+), 41 deletions(-) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ValidateUtil.java create mode 100644 hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemDao.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java create mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index af51741bc5d..f6c6a2e2bbc 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -588,7 +588,10 @@ class ModelScanner { */ List> refTypesList = new ArrayList>(); for (Class nextType : childAnnotation.type()) { - if (IBaseResource.class.isAssignableFrom(nextType) == false) { + if (IBaseReference.class.isAssignableFrom(nextType)) { + refTypesList.add(myVersion.isRi() ? IAnyResource.class : IResource.class); + continue; + } else if (IBaseResource.class.isAssignableFrom(nextType) == false) { throw new ConfigurationException("Field '" + next.getName() + "' in class '" + next.getDeclaringClass().getCanonicalName() + "' is of type " + BaseResourceReferenceDt.class + " but contains a non-resource type: " + nextType.getCanonicalName()); } refTypesList.add((Class) nextType); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ValidateUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ValidateUtil.java new file mode 100644 index 00000000000..177a2c00795 --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ValidateUtil.java @@ -0,0 +1,21 @@ +package ca.uhn.fhir.util; + +import static org.apache.commons.lang3.StringUtils.isBlank; + +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; + +public class ValidateUtil { + + public static void isNotNullOrThrowInvalidRequest(boolean theSuccess, String theMessage) { + if (theSuccess == false) { + throw new InvalidRequestException(theMessage); + } + } + + public static void isNotBlankOrThrowInvalidRequest(String theString, String theMessage) { + if (isBlank(theString)) { + throw new InvalidRequestException(theMessage); + } + } + +} diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties index c8910c7f7b2..fcde6e42738 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties @@ -65,4 +65,6 @@ ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.successfulCreate=Successfully create ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.successfulUpdate=Successfully updated resource "{0}" in {1}ms ca.uhn.fhir.jpa.dao.SearchBuilder.invalidQuantityPrefix=Unable to handle quantity prefix "{0}" for value: {1} -ca.uhn.fhir.jpa.dao.SearchBuilder.invalidNumberPrefix=Unable to handle number prefix "{0}" for value: {1} \ No newline at end of file +ca.uhn.fhir.jpa.dao.SearchBuilder.invalidNumberPrefix=Unable to handle number prefix "{0}" for value: {1} + +ca.uhn.fhir.jpa.term.TerminologySvcImpl.cannotCreateDuplicateCodeSystemUri=Can not create multiple code systems with URI "{0}", already have one with resource ID: {1} \ No newline at end of file diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java new file mode 100644 index 00000000000..89e9c415253 --- /dev/null +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java @@ -0,0 +1,50 @@ +package ca.uhn.fhir.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; + +public class ValidateUtilTest { + + @Test + public void testValidate() { + ValidateUtil.isNotNullOrThrowInvalidRequest(true, ""); + + try { + ValidateUtil.isNotNullOrThrowInvalidRequest(false, "The message"); + fail(); + } catch (InvalidRequestException e) { + assertEquals("The message", e.getMessage()); + } + } + + @Test + public void testIsNotBlank() { + ValidateUtil.isNotBlankOrThrowInvalidRequest("aa", ""); + + try { + ValidateUtil.isNotBlankOrThrowInvalidRequest("", "The message"); + fail(); + } catch (InvalidRequestException e) { + assertEquals("The message", e.getMessage()); + } + + try { + ValidateUtil.isNotBlankOrThrowInvalidRequest(null, "The message"); + fail(); + } catch (InvalidRequestException e) { + assertEquals("The message", e.getMessage()); + } + + try { + ValidateUtil.isNotBlankOrThrowInvalidRequest(" ", "The message"); + fail(); + } catch (InvalidRequestException e) { + assertEquals("The message", e.getMessage()); + } + } + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index ded23af9b26..d9c22c8bbd4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.config; import javax.annotation.Resource; +import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -37,6 +38,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.term.ITerminologySvc; +import ca.uhn.fhir.jpa.term.TerminologySvcImpl; @Configuration @EnableScheduling @@ -95,6 +98,11 @@ public class BaseConfig implements SchedulingConfigurer { return ourFhirContextDstu3; } + @Bean(autowire=Autowire.BY_TYPE) + public ITerminologySvc terminologyService() { + return new TerminologySvcImpl(); + } + @Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler retVal = new ThreadPoolTaskScheduler(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java index 41e9614d380..b67c83c5643 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java @@ -571,9 +571,14 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { } } + + ourLog.info("Flushing context after {}", theActionName); + myEntityManager.flush(); long delay = System.currentTimeMillis() - start; - ourLog.info(theActionName + " completed in {}ms", new Object[] { delay }); + int numEntries = theRequest.getEntry().size(); + long delayPer = delay / numEntries; + ourLog.info("{} completed in {}ms ({} entries at {}ms per entry)", new Object[] { theActionName , delay, numEntries, delayPer }); response.setType(BundleTypeEnum.TRANSACTION_RESPONSE); return response; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemDao.java new file mode 100644 index 00000000000..059a9afd90c --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemDao.java @@ -0,0 +1,34 @@ +package ca.uhn.fhir.jpa.dao.data; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2016 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 org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import ca.uhn.fhir.jpa.entity.TermCodeSystem; + +public interface ITermCodeSystemDao extends JpaRepository { + + @Query("SELECT cs FROM TermCodeSystem cs WHERE cs.myCodeSystemUri = :code_system_uri") + TermCodeSystem findByCodeSystemUri(@Param("code_system_uri") String theCodeSystemUri); + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java new file mode 100644 index 00000000000..0c30371a4e2 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java @@ -0,0 +1,34 @@ +package ca.uhn.fhir.jpa.dao.data; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2016 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 org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; + +public interface ITermCodeSystemVersionDao extends JpaRepository { + + @Query("SELECT cs FROM TermCodeSystemVersion cs WHERE cs.myResource.myId = :resource_id AND cs.myResourceVersionId = :version_id") + TermCodeSystemVersion findByCodeSystemResourceAndVersion(@Param("resource_id") Long theCodeSystemResourcePid, @Param("version_id") Long theCodeSystemVersionPid); + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java new file mode 100644 index 00000000000..41ec4c1f31a --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java @@ -0,0 +1,35 @@ +package ca.uhn.fhir.jpa.dao.data; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2016 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 org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; +import ca.uhn.fhir.jpa.entity.TermConcept; + +public interface ITermConceptDao extends JpaRepository { + + @Query("SELECT c FROM TermConcept c WHERE c.myCodeSystem = :code_system AND c.myCode = :code") + TermConcept findByCodeSystemAndCode(@Param("code_system") TermCodeSystemVersion theCodeSystem, @Param("code") String theCode); + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java new file mode 100644 index 00000000000..6216eb19f4c --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java @@ -0,0 +1,29 @@ +package ca.uhn.fhir.jpa.dao.data; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2016 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 org.springframework.data.jpa.repository.JpaRepository; + +import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; + +public interface ITermConceptParentChildLinkDao extends JpaRepository { + // nothing +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystem.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystem.java index 135fd7635ec..f45f3edf551 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystem.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystem.java @@ -25,6 +25,7 @@ import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; @@ -34,24 +35,39 @@ import javax.persistence.UniqueConstraint; //@formatter:off @Table(name="TRM_CODESYSTEM", uniqueConstraints= { - @UniqueConstraint(name="IDX_CS_RESOURCEPID", columnNames= {"RES_ID"}) + @UniqueConstraint(name="IDX_CS_CODESYSTEM", columnNames= {"CODE_SYSTEM_URI"}) }) @Entity() //@formatter:on public class TermCodeSystem implements Serializable { private static final long serialVersionUID = 1L; - @Id() - @SequenceGenerator(name="SEQ_CODESYSTEM_PID", sequenceName="SEQ_CODESYSTEM_PID") - @GeneratedValue() - @Column(name="PID") - private Long myPid; - - @OneToOne() - @JoinColumn(name="RES_ID", referencedColumnName="RES_ID", nullable=false, updatable=false) - private ResourceTable myResource; - - @Column(name="RES_VERSION_ID", nullable=false, updatable=false) - private Long myResourceVersionId; + @Column(name="CODE_SYSTEM_URI", nullable=false) + private String myCodeSystemUri; + @Id() + @SequenceGenerator(name = "SEQ_CODESYSTEM_PID", sequenceName = "SEQ_CODESYSTEM_PID") + @GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CODESYSTEM_PID") + @Column(name = "PID") + private Long myPid; + + @OneToOne() + @JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false) + private ResourceTable myResource; + + public String getCodeSystemUri() { + return myCodeSystemUri; + } + + public ResourceTable getResource() { + return myResource; + } + + public void setCodeSystemUri(String theCodeSystemUri) { + myCodeSystemUri = theCodeSystemUri; + } + + public void setResource(ResourceTable theResource) { + myResource = theResource; + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java new file mode 100644 index 00000000000..4d1f35de323 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java @@ -0,0 +1,88 @@ +package ca.uhn.fhir.jpa.entity; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2016 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 java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +//@formatter:off +@Table(name="TRM_CODESYSTEM_VER", uniqueConstraints= { + @UniqueConstraint(name="IDX_CSV_RESOURCEPID_AND_VER", columnNames= {"RES_ID", "RES_VERSION_ID"}) +}) +@Entity() +//@formatter:on +public class TermCodeSystemVersion implements Serializable { + private static final long serialVersionUID = 1L; + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "myCodeSystem") + private Collection myConcepts; + + @Id() + @SequenceGenerator(name = "SEQ_CODESYSTEMVER_PID", sequenceName = "SEQ_CODESYSTEMVER_PID") + @GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CODESYSTEMVER_PID") + @Column(name = "PID") + private Long myPid; + + @OneToOne() + @JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false) + private ResourceTable myResource; + + @Column(name = "RES_VERSION_ID", nullable = false, updatable = false) + private Long myResourceVersionId; + + public Collection getConcepts() { + if (myConcepts == null) { + myConcepts = new ArrayList(); + } + return myConcepts; + } + + public ResourceTable getResource() { + return myResource; + } + + public Long getResourceVersionId() { + return myResourceVersionId; + } + + public void setResource(ResourceTable theResource) { + myResource = theResource; + } + + public void setResourceVersionId(Long theResourceVersionId) { + myResourceVersionId = theResourceVersionId; + } + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java index 53be0e78bfd..753d7db7ae9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java @@ -21,36 +21,138 @@ package ca.uhn.fhir.jpa.entity; */ import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.ForeignKey; import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; @Entity -@Table(name="TRM_CONCEPT") +@Table(name="TRM_CONCEPT", uniqueConstraints= { + @UniqueConstraint(name="IDX_CONCEPT_CS_CODE", columnNames= {"CODESYSTEM_PID", "CODE"}) +}) public class TermConcept implements Serializable { private static final long serialVersionUID = 1L; - @Id() - @SequenceGenerator(name="SEQ_CONCEPT_PID", sequenceName="SEQ_CONCEPT_PID") - @GeneratedValue() - @Column(name="PID") - private Long myPid; + @OneToMany(fetch=FetchType.LAZY, mappedBy="myParent") + private Collection myChildren; - @ManyToOne() - @JoinColumn(name="CODESYSTEM_PID", referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_CONCEPT_PID_CS_PID")) - private TermCodeSystem myCodeSystem; - @Column(name="CODE", length=100, nullable=false) private String myCode; + @ManyToOne() + @JoinColumn(name="CODESYSTEM_PID", referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_CONCEPT_PID_CS_PID")) + private TermCodeSystemVersion myCodeSystem; + @Column(name="DISPLAY", length=200, nullable=true) private String myDisplay; + + @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="myChild") + private Collection myParents; + + @Id() + @SequenceGenerator(name="SEQ_CONCEPT_PID", sequenceName="SEQ_CONCEPT_PID") + @GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CONCEPT_PID") + @Column(name="PID") + private Long myPid; + + public TermConcept() { + super(); + } + + public TermConcept(TermCodeSystemVersion theCs, String theCode) { + setCodeSystem(theCs); + setCode(theCode); + } + + public TermConcept addChild(TermConcept theChild) { + Validate.notNull(theChild.getCodeSystem(), "theChild.getCodeSystem() must not return null"); + TermConceptParentChildLink link = new TermConceptParentChildLink(); + link.setParent(this); + link.setCodeSystem(theChild.getCodeSystem()); + link.setChild(theChild); + getChildren().add(link); + return this; + } + + @Override + public boolean equals(Object theObj) { + if (!(theObj instanceof TermConcept)) { + return false; + } + if (theObj == this) { + return true; + } + + TermConcept obj = (TermConcept)theObj; + if (obj.myPid == null) { + return false; + } + + EqualsBuilder b = new EqualsBuilder(); + b.append(myPid, obj.myPid); + return b.isEquals(); + } + + public Collection getChildren() { + if (myChildren == null) { + myChildren = new ArrayList(); + } + return myChildren; + } + + public String getCode() { + return myCode; + } + + public TermCodeSystemVersion getCodeSystem() { + return myCodeSystem; + } + + public String getDisplay() { + return myDisplay; + } + + public Collection getParents() { + if (myParents == null) { + myParents = new ArrayList(); + } + return myParents; + } + @Override + public int hashCode() { + HashCodeBuilder b = new HashCodeBuilder(); + b.append(myPid); + return b.toHashCode(); + } + + public void setCode(String theCode) { + myCode = theCode; + } + + public void setCodeSystem(TermCodeSystemVersion theCodeSystem) { + myCodeSystem = theCodeSystem; + } + + public void setDisplay(String theDisplay) { + myDisplay = theDisplay; + } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptParentChildLink.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptParentChildLink.java index 66b877453f8..287af9bb4a1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptParentChildLink.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptParentChildLink.java @@ -24,7 +24,9 @@ import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.ForeignKey; import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -32,26 +34,50 @@ import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name="TRM_CONCEPT") +@Table(name="TRM_CONCEPT_PC_LINK") public class TermConceptParentChildLink implements Serializable { private static final long serialVersionUID = 1L; - + + @ManyToOne() + @JoinColumn(name="CHILD_PID", nullable=false, referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_TERM_CONCEPTPC_CHILD")) + private TermConcept myChild; + + @ManyToOne() + @JoinColumn(name="CODESYSTEM_PID", nullable=false, foreignKey=@ForeignKey(name="FK_TERM_CONCEPTPC_CS")) + private TermCodeSystemVersion myCodeSystem; + + @ManyToOne() + @JoinColumn(name="PARENT_PID", nullable=false, referencedColumnName="PID", foreignKey=@ForeignKey(name="FK_TERM_CONCEPTPC_PARENT")) + private TermConcept myParent; + @Id() @SequenceGenerator(name="SEQ_CONCEPT_PC_PID", sequenceName="SEQ_CONCEPT_PC_PID") - @GeneratedValue() + @GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_CONCEPT_PC_PID") @Column(name="PID") private Long myPid; - @ManyToOne - @JoinColumn(name="PARENT_PID", nullable=false) - private TermConcept myParent; - - @ManyToOne - @JoinColumn(name="CHILD_PID", nullable=false) - private TermConcept myChild; + public TermConcept getChild() { + return myChild; + } - @ManyToOne - @JoinColumn(name="CODESYSTEM_PID", nullable=false) - private TermCodeSystem myCodeSystem; + public TermCodeSystemVersion getCodeSystem() { + return myCodeSystem; + } + + public TermConcept getParent() { + return myParent; + } + + public void setChild(TermConcept theChild) { + myChild = theChild; + } + + public void setCodeSystem(TermCodeSystemVersion theCodeSystem) { + myCodeSystem = theCodeSystem; + } + + public void setParent(TermConcept theParent) { + myParent = theParent; + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ITerminologySvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ITerminologySvc.java index 26d7bfccd24..5903ddbb732 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ITerminologySvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ITerminologySvc.java @@ -1,5 +1,14 @@ package ca.uhn.fhir.jpa.term; +import java.util.Set; + +import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; +import ca.uhn.fhir.jpa.entity.TermConcept; + public interface ITerminologySvc { + void storeNewCodeSystemVersion(String theSystemUri, TermCodeSystemVersion theCodeSytem); + + Set findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemResourceVersion, String theCode); + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologySvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologySvcImpl.java index ffd0dc7652f..5e5a6702830 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologySvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologySvcImpl.java @@ -1,6 +1,136 @@ package ca.uhn.fhir.jpa.term; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.Set; + +import javax.transaction.Transactional; +import javax.transaction.Transactional.TxType; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.ValidationUtils; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao; +import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao; +import ca.uhn.fhir.jpa.dao.data.ITermConceptDao; +import ca.uhn.fhir.jpa.dao.data.ITermConceptParentChildLinkDao; +import ca.uhn.fhir.jpa.entity.TermCodeSystem; +import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; +import ca.uhn.fhir.jpa.entity.TermConcept; +import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.util.ObjectUtil; +import ca.uhn.fhir.util.ValidateUtil; + public class TerminologySvcImpl implements ITerminologySvc { + private static final Object PLACEHOLDER_OBJECT = new Object(); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TerminologySvcImpl.class); + + @Autowired + private ITermCodeSystemVersionDao myCodeSystemVersionDao; + + @Autowired + private ITermConceptParentChildLinkDao myConceptParentChildLinkDao; + + @Autowired + private ITermConceptDao myConceptDao; + + @Autowired + private ITermCodeSystemDao myCodeSystemDao; + + @Autowired + private FhirContext myContext; + + + @Override + @Transactional(value=TxType.REQUIRED) + public void storeNewCodeSystemVersion(String theSystemUri, TermCodeSystemVersion theCodeSystem) { + ourLog.info("Storing code system"); + + ValidateUtil.isNotNullOrThrowInvalidRequest(theCodeSystem.getResource() != null, "No resource supplied"); + ValidateUtil.isNotBlankOrThrowInvalidRequest(theSystemUri, "No system URI supplied"); + + TermCodeSystem codeSystem = myCodeSystemDao.findByCodeSystemUri(theSystemUri); + if (codeSystem == null) { + TermCodeSystem newCodeSystem = new TermCodeSystem(); + newCodeSystem.setResource(theCodeSystem.getResource()); + newCodeSystem.setCodeSystemUri(theSystemUri); + myCodeSystemDao.save(newCodeSystem); + } else { + if (!ObjectUtil.equals(codeSystem.getResource().getId(), theCodeSystem.getResource().getId())) { + throw new InvalidRequestException(myContext.getLocalizer().getMessage(TerminologySvcImpl.class, "cannotCreateDuplicateCodeSystemUri", theSystemUri, codeSystem.getResource().getIdDt().getValue())); + } + } + + // Validate the code system + IdentityHashMap conceptsStack = new IdentityHashMap(); + for (TermConcept next : theCodeSystem.getConcepts()) { + validateConceptForStorage(next, theCodeSystem, conceptsStack); + } + + myCodeSystemVersionDao.save(theCodeSystem); + + conceptsStack = new IdentityHashMap(); + for (TermConcept next : theCodeSystem.getConcepts()) { + persistChildren(next, theCodeSystem, conceptsStack); + } + } + + private void persistChildren(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap theConceptsStack) { + if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) { + return; + } + + for (TermConceptParentChildLink next : theConcept.getChildren()) { + persistChildren(next.getChild(), theCodeSystem, theConceptsStack); + } + + myConceptDao.save(theConcept); + + for (TermConceptParentChildLink next : theConcept.getChildren()) { + myConceptParentChildLinkDao.save(next); + } + } + + private void validateConceptForStorage(TermConcept theConcept, TermCodeSystemVersion theCodeSystem, IdentityHashMap theConceptsStack) { + ValidateUtil.isNotNullOrThrowInvalidRequest(theConcept.getCodeSystem() == theCodeSystem, "Codesystem contains a code which does not reference the codesystem"); + ValidateUtil.isNotBlankOrThrowInvalidRequest(theConcept.getCode(), "Codesystem contains a code which does not reference the codesystem"); + + if (theConceptsStack.put(theConcept, PLACEHOLDER_OBJECT) != null) { + throw new InvalidRequestException("CodeSystem contains circular reference around code " + theConcept.getCode()); + } + + for (TermConceptParentChildLink next : theConcept.getChildren()) { + validateConceptForStorage(next.getChild(), theCodeSystem, theConceptsStack); + } + + theConceptsStack.remove(theConcept); + } + + @Transactional(value=TxType.REQUIRED) + @Override + public Set findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemVersionPid, String theCode) { + TermCodeSystemVersion codeSystem = myCodeSystemVersionDao.findByCodeSystemResourceAndVersion(theCodeSystemResourcePid, theCodeSystemVersionPid); + TermConcept concept = myConceptDao.findByCodeSystemAndCode(codeSystem, theCode); + + Set retVal = new HashSet(); + retVal.add(concept); + + fetchChildren(concept, retVal); + + return retVal; + } + + private void fetchChildren(TermConcept theConcept, Set theSetToPopulate) { + for (TermConceptParentChildLink nextChildLink : theConcept.getChildren()) { + TermConcept nextChild = nextChildLink.getChild(); + if (theSetToPopulate.add(nextChild)) { + fetchChildren(nextChild, theSetToPopulate); + } + } + } + diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java index 398d137f2c8..ffb25854525 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java @@ -13,6 +13,7 @@ import org.hibernate.search.jpa.FullTextEntityManager; import org.hibernate.search.jpa.Search; import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport; import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.ConceptMap; @@ -61,6 +62,7 @@ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.ISearchDao; +import ca.uhn.fhir.jpa.dao.data.IResourceTableDao; import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest; import ca.uhn.fhir.jpa.entity.ForcedId; import ca.uhn.fhir.jpa.entity.ResourceHistoryTable; @@ -78,7 +80,12 @@ import ca.uhn.fhir.jpa.entity.ResourceTag; import ca.uhn.fhir.jpa.entity.SubscriptionFlaggedResource; import ca.uhn.fhir.jpa.entity.SubscriptionTable; import ca.uhn.fhir.jpa.entity.TagDefinition; +import ca.uhn.fhir.jpa.entity.TermCodeSystem; +import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; +import ca.uhn.fhir.jpa.entity.TermConcept; +import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3; +import ca.uhn.fhir.jpa.term.ITerminologySvc; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.method.MethodUtil; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; @@ -88,6 +95,10 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; @ContextConfiguration(classes= {TestDstu3Config.class}) //@formatter:on public abstract class BaseJpaDstu3Test extends BaseJpaTest { + @Autowired + protected IResourceTableDao myResourceTableDao; + @Autowired + protected ITerminologySvc myTermSvc; @Autowired @Qualifier("myJpaValidationSupportChainDstu3") protected IValidationSupport myValidationSupport; @@ -99,6 +110,9 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { @Qualifier("myConceptMapDaoDstu3") protected IFhirResourceDao myConceptMapDao; @Autowired + @Qualifier("myCodeSystemDaoDstu3") + protected IFhirResourceDao myCodeSystemDao; + @Autowired @Qualifier("myMedicationDaoDstu3") protected IFhirResourceDao myMedicationDao; @Autowired @@ -241,6 +255,16 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { return null; } }); + txTemplate.execute(new TransactionCallback() { + @Override + public Void doInTransaction(TransactionStatus theStatus) { + entityManager.createQuery("DELETE from " + TermConceptParentChildLink.class.getSimpleName() + " d").executeUpdate(); + entityManager.createQuery("DELETE from " + TermConcept.class.getSimpleName() + " d").executeUpdate(); + entityManager.createQuery("DELETE from " + TermCodeSystemVersion.class.getSimpleName() + " d").executeUpdate(); + entityManager.createQuery("DELETE from " + TermCodeSystem.class.getSimpleName() + " d").executeUpdate(); + return null; + } + }); txTemplate.execute(new TransactionCallback() { @Override public Void doInTransaction(TransactionStatus theStatus) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java new file mode 100644 index 00000000000..404398e084e --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java @@ -0,0 +1,151 @@ +package ca.uhn.fhir.jpa.term; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.*; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.hl7.fhir.dstu3.model.CodeSystem; +import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.Test; + +import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test; +import ca.uhn.fhir.jpa.entity.ResourceTable; +import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; +import ca.uhn.fhir.jpa.entity.TermConcept; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; + +public class TerminologySvcImplTest extends BaseJpaDstu3Test { + + @Test + public void testStoreCodeSystemInvalidCyclicLoop() { + CodeSystem codeSystem = new CodeSystem(); + codeSystem.setUrl("http://example.com/my_code_system"); + codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); + IIdType id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + + ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); + + TermCodeSystemVersion cs = new TermCodeSystemVersion(); + cs.setResource(table); + cs.setResourceVersionId(table.getVersion()); + + TermConcept parent = new TermConcept(); + parent.setCodeSystem(cs); + parent.setCode("parent"); + cs.getConcepts().add(parent); + + TermConcept child = new TermConcept(); + child.setCodeSystem(cs); + child.setCode("child"); + parent.addChild(child); + + child.addChild(parent); + + try { + myTermSvc.storeNewCodeSystemVersion("http://foo", cs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("CodeSystem contains circular reference around code parent", e.getMessage()); + } + } + + @Test + public void testFetchIsA() { + CodeSystem codeSystem = new CodeSystem(); + codeSystem.setUrl("http://example.com/my_code_system"); + codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); + IIdType id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + + ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); + + TermCodeSystemVersion cs = new TermCodeSystemVersion(); + cs.setResource(table); + cs.setResourceVersionId(table.getVersion()); + + TermConcept parentA = new TermConcept(cs, "ParentA"); + cs.getConcepts().add(parentA); + + TermConcept childAA = new TermConcept(cs, "childAA"); + parentA.addChild(childAA); + + TermConcept childAAA = new TermConcept(cs, "childAAA"); + childAA.addChild(childAAA); + + TermConcept childAAB = new TermConcept(cs, "childAAB"); + childAA.addChild(childAAB); + + TermConcept childAB = new TermConcept(cs, "childAB"); + parentA.addChild(childAB); + + TermConcept parentB = new TermConcept(cs, "ParentB"); + cs.getConcepts().add(parentB); + + myTermSvc.storeNewCodeSystemVersion("http://foo", cs); + + Set concepts; + Set codes; + + concepts = myTermSvc.findCodesBelow(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "ParentA"); + codes = toCodes(concepts); + assertThat(codes, containsInAnyOrder("ParentA", "childAA", "childAAA", "childAAB", "childAB")); + + concepts = myTermSvc.findCodesBelow(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "childAA"); + codes = toCodes(concepts); + assertThat(codes, containsInAnyOrder("childAA", "childAAA", "childAAB")); + } + + @Test + public void testCreateDuplicateCodeSystemUri() { + CodeSystem codeSystem = new CodeSystem(); + codeSystem.setUrl("http://example.com/my_code_system"); + codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); + IIdType id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + + ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); + + TermCodeSystemVersion cs = new TermCodeSystemVersion(); + cs.setResource(table); + cs.setResourceVersionId(table.getVersion()); + + myTermSvc.storeNewCodeSystemVersion("http://example.com/my_code_system", cs); + + // Update + cs = new TermCodeSystemVersion(); + TermConcept parentA = new TermConcept(cs, "ParentA"); + cs.getConcepts().add(parentA); + id = myCodeSystemDao.update(codeSystem).getId().toUnqualified(); + table = myResourceTableDao.findOne(id.getIdPartAsLong()); + cs.setResource(table); + cs.setResourceVersionId(table.getVersion()); + myTermSvc.storeNewCodeSystemVersion("http://example.com/my_code_system", cs); + + // Try to update to a different resource + codeSystem = new CodeSystem(); + codeSystem.setUrl("http://example.com/my_code_system"); + codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); + id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + table = myResourceTableDao.findOne(id.getIdPartAsLong()); + cs.setResource(table); + cs.setResourceVersionId(table.getVersion()); + try { + myTermSvc.storeNewCodeSystemVersion("http://example.com/my_code_system", cs); + fail(); + } catch (InvalidRequestException e) { + assertThat(e.getMessage(), containsString("Can not create multiple code systems with URI \"http://example.com/my_code_system\", already have one with resource ID: CodeSystem/")); + } + + } + + private Set toCodes(Set theConcepts) { + HashSet retVal = new HashSet(); + for (TermConcept next : theConcepts) { + retVal.add(next.getCode()); + } + return retVal; + } +} diff --git a/hapi-fhir-structures-dstu3/src/main/resources/org/hl7/fhir/dstu3/model/fhirversion.properties b/hapi-fhir-structures-dstu3/src/main/resources/org/hl7/fhir/dstu3/model/fhirversion.properties index 8c1ea05b949..c55ce02715e 100644 --- a/hapi-fhir-structures-dstu3/src/main/resources/org/hl7/fhir/dstu3/model/fhirversion.properties +++ b/hapi-fhir-structures-dstu3/src/main/resources/org/hl7/fhir/dstu3/model/fhirversion.properties @@ -13,6 +13,7 @@ resource.CarePlan=org.hl7.fhir.dstu3.model.CarePlan resource.Claim=org.hl7.fhir.dstu3.model.Claim resource.ClaimResponse=org.hl7.fhir.dstu3.model.ClaimResponse resource.ClinicalImpression=org.hl7.fhir.dstu3.model.ClinicalImpression +resource.CodeSystem=org.hl7.fhir.dstu3.model.CodeSystem resource.Communication=org.hl7.fhir.dstu3.model.Communication resource.CommunicationRequest=org.hl7.fhir.dstu3.model.CommunicationRequest resource.Composition=org.hl7.fhir.dstu3.model.Composition @@ -54,6 +55,7 @@ resource.Immunization=org.hl7.fhir.dstu3.model.Immunization resource.ImmunizationRecommendation=org.hl7.fhir.dstu3.model.ImmunizationRecommendation resource.ImplementationGuide=org.hl7.fhir.dstu3.model.ImplementationGuide resource.Library=org.hl7.fhir.dstu3.model.Library +resource.Linkage=org.hl7.fhir.dstu3.model.Linkage resource.List=org.hl7.fhir.dstu3.model.ListResource resource.Location=org.hl7.fhir.dstu3.model.Location resource.Measure=org.hl7.fhir.dstu3.model.Measure @@ -85,6 +87,7 @@ resource.Procedure=org.hl7.fhir.dstu3.model.Procedure resource.ProcedureRequest=org.hl7.fhir.dstu3.model.ProcedureRequest resource.ProcessRequest=org.hl7.fhir.dstu3.model.ProcessRequest resource.ProcessResponse=org.hl7.fhir.dstu3.model.ProcessResponse +resource.Protocol=org.hl7.fhir.dstu3.model.Protocol resource.Provenance=org.hl7.fhir.dstu3.model.Provenance resource.Questionnaire=org.hl7.fhir.dstu3.model.Questionnaire resource.QuestionnaireResponse=org.hl7.fhir.dstu3.model.QuestionnaireResponse diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java index 29b00e55e34..6ee11880454 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.UUID; import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.util.IO; import org.hamcrest.Matchers; import org.hl7.fhir.dstu3.model.Binary; import org.hl7.fhir.dstu3.model.Bundle; @@ -37,6 +36,7 @@ import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.HumanName; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse; +import org.hl7.fhir.dstu3.model.Linkage; import org.hl7.fhir.dstu3.model.Medication; import org.hl7.fhir.dstu3.model.MedicationOrder; import org.hl7.fhir.dstu3.model.Observation; @@ -46,7 +46,6 @@ import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Quantity; import org.hl7.fhir.dstu3.model.QuestionnaireResponse; import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.Specimen; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.utilities.xhtml.XhtmlNode; @@ -71,6 +70,15 @@ public class JsonParserDstu3Test { ourCtx.setNarrativeGenerator(null); } + @Test + public void testLinkage() { + Linkage l = new Linkage(); + l.addItem().getResource().setDisplay("FOO"); + String out = ourCtx.newXmlParser().encodeResourceToString(l); + ourLog.info(out); + assertEquals("", out); + } + @Test public void testEncodeAndParseExtensions() throws Exception { diff --git a/hapi-tinder-plugin/.classpath b/hapi-tinder-plugin/.classpath index fafda0399f3..4efeb48e6cf 100644 --- a/hapi-tinder-plugin/.classpath +++ b/hapi-tinder-plugin/.classpath @@ -22,6 +22,7 @@ + From 4975d212fabc44f3c8ae39327f887bbffdfe9b30 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 17 Feb 2016 08:05:55 -0500 Subject: [PATCH 2/6] Add userdata map to interceptors which can be passed around --- .../uhn/fhir/rest/method/RequestDetails.java | 144 +++--- .../interceptor/IServerInterceptor.java | 152 +++--- .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 12 +- .../fhir/jpa/dao/BaseHapiFhirResourceDao.java | 111 ++-- .../fhir/jpa/dao/BaseHapiFhirSystemDao.java | 21 +- .../fhir/jpa/dao/FhirResourceDaoDstu1.java | 3 +- .../fhir/jpa/dao/FhirResourceDaoDstu2.java | 5 +- .../jpa/dao/FhirResourceDaoPatientDstu2.java | 9 +- ...ResourceDaoQuestionnaireResponseDstu2.java | 17 +- .../FhirResourceDaoSearchParameterDstu2.java | 7 +- .../dao/FhirResourceDaoSubscriptionDstu2.java | 12 +- .../jpa/dao/FhirResourceDaoValueSetDstu2.java | 3 +- .../uhn/fhir/jpa/dao/FhirSystemDaoDstu1.java | 6 +- .../uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java | 18 +- .../ca/uhn/fhir/jpa/dao/IFhirResourceDao.java | 60 ++- .../fhir/jpa/dao/IFhirResourceDaoPatient.java | 5 +- .../jpa/dao/IFhirResourceDaoValueSet.java | 4 +- .../ca/uhn/fhir/jpa/dao/IFhirSystemDao.java | 12 +- .../uhn/fhir/jpa/dao/SearchParameterMap.java | 54 +- .../jpa/dao/dstu3/FhirResourceDaoDstu3.java | 5 +- .../dstu3/FhirResourceDaoPatientDstu3.java | 9 +- ...ResourceDaoQuestionnaireResponseDstu3.java | 16 +- .../FhirResourceDaoSearchParameterDstu3.java | 7 +- .../FhirResourceDaoSubscriptionDstu3.java | 12 +- .../dstu3/FhirResourceDaoValueSetDstu3.java | 5 +- .../jpa/dao/dstu3/FhirSystemDaoDstu3.java | 18 +- .../jpa/provider/BaseJpaResourceProvider.java | 21 +- .../BaseJpaResourceProviderPatientDstu2.java | 15 +- .../BaseJpaResourceProviderValueSetDstu2.java | 6 +- .../jpa/provider/BaseJpaSystemProvider.java | 9 +- .../provider/JpaResourceProviderDstu1.java | 15 +- .../provider/JpaResourceProviderDstu2.java | 44 +- .../jpa/provider/JpaSystemProviderDstu2.java | 4 +- .../BaseJpaResourceProviderPatientDstu3.java | 15 +- .../BaseJpaResourceProviderValueSetDstu3.java | 6 +- .../dstu3/JpaResourceProviderDstu3.java | 43 +- .../dstu3/JpaSystemProviderDstu3.java | 4 +- .../SubscriptionWebsocketHandlerDstu2.java | 7 +- .../SubscriptionWebsocketHandlerDstu3.java | 7 +- ...quireManualActivationInterceptorDstu2.java | 3 +- ...quireManualActivationInterceptorDstu3.java | 3 +- .../jpa/dao/FhirResourceDaoDstu1Test.java | 24 +- .../fhir/jpa/dao/FhirSystemDaoDstu1Test.java | 51 +- .../FhirResourceDaoDstu2InterceptorTest.java | 17 +- .../FhirResourceDaoDstu2SearchFtTest.java | 87 ++-- .../FhirResourceDaoDstu2SearchNoFtTest.java | 253 ++++----- .../FhirResourceDaoDstu2SubscriptionTest.java | 83 +-- .../dao/dstu2/FhirResourceDaoDstu2Test.java | 459 ++++++++--------- .../dstu2/FhirResourceDaoDstu2UpdateTest.java | 67 +-- .../FhirResourceDaoDstu2ValidateTest.java | 52 +- .../FhirResourceDaoValueSetDstu2Test.java | 3 +- .../jpa/dao/dstu2/FhirSearchDaoDstu2Test.java | 11 +- .../jpa/dao/dstu2/FhirSystemDaoDstu2Test.java | 137 ++--- .../FhirResourceDaoDstu3InterceptorTest.java | 17 +- .../FhirResourceDaoDstu3SearchFtTest.java | 97 ++-- .../FhirResourceDaoDstu3SearchNoFtTest.java | 271 +++++----- .../FhirResourceDaoDstu3SubscriptionTest.java | 85 ++-- .../dao/dstu3/FhirResourceDaoDstu3Test.java | 480 +++++++++--------- .../dstu3/FhirResourceDaoDstu3UpdateTest.java | 67 +-- .../FhirResourceDaoDstu3ValidateTest.java | 55 +- .../FhirResourceDaoValueSetDstu3Test.java | 3 +- .../jpa/dao/dstu3/FhirSearchDaoDstu3Test.java | 11 +- .../jpa/dao/dstu3/FhirSystemDaoDstu3Test.java | 143 +++--- .../provider/ResourceProviderDstu1Test.java | 3 +- .../provider/ResourceProviderDstu2Test.java | 33 +- .../ResourceProviderDstu2ValueSetTest.java | 3 +- .../jpa/provider/SubscriptionsDstu2Test.java | 31 +- .../jpa/provider/SystemProviderDstu2Test.java | 15 +- .../dstu3/ResourceProviderDstu3Test.java | 35 +- .../ResourceProviderDstu3ValueSetTest.java | 3 +- ...roviderQuestionnaireResponseDstu3Test.java | 13 +- .../dstu3/SubscriptionsDstu3Test.java | 31 +- .../dstu3/SystemProviderDstu3Test.java | 21 +- .../fhir/jpa/term/TerminologySvcImplTest.java | 11 +- .../InterceptorUserDataMapDstu2Test.java | 277 ++++++++++ .../resources/vm/jpa_resource_provider.vm | 5 +- src/changes/changes.xml | 12 + 77 files changed, 2164 insertions(+), 1731 deletions(-) create mode 100644 hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java index 47129480bcf..4325c567dad 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java @@ -37,24 +37,27 @@ import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.server.IRestfulResponse; import ca.uhn.fhir.rest.server.IRestfulServerDefaults; +import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; public abstract class RequestDetails { - private byte[] myRequestContents; private String myCompartmentName; private String myCompleteUrl; private String myFhirServerBase; private IIdType myId; private String myOperation; private Map myParameters; + private byte[] myRequestContents; private String myRequestPath; private RequestTypeEnum myRequestType; private String myResourceName; private boolean myRespondGzip; + private IRestfulResponse myResponse; private RestOperationTypeEnum myRestOperationType; private String mySecondaryOperation; private Map> myUnqualifiedToQualifiedNames; - private IRestfulResponse myResponse; + private Map myUserData; + protected abstract byte[] getByteStreamRequestContents(); public String getCompartmentName() { return myCompartmentName; @@ -73,10 +76,28 @@ public abstract class RequestDetails { return myFhirServerBase; } + public abstract String getHeader(String name); + + public abstract List getHeaders(String name); + public IIdType getId() { return myId; } + /** + * Retrieves the body of the request as binary data. Either this method or {@link #getReader} may be called to read + * the body, not both. + * + * @return a {@link InputStream} object containing the body of the request + * + * @exception IllegalStateException + * if the {@link #getReader} method has already been called for this request + * + * @exception IOException + * if an input or output exception occurred + */ + public abstract InputStream getInputStream() throws IOException; + public String getOperation() { return myOperation; } @@ -85,6 +106,26 @@ public abstract class RequestDetails { return myParameters; } + /** + * Retrieves the body of the request as character data using a BufferedReader. The reader translates the + * character data according to the character encoding used on the body. Either this method or {@link #getInputStream} + * may be called to read the body, not both. + * + * @return a Reader containing the body of the request + * + * @exception UnsupportedEncodingException + * if the character set encoding used is not supported and the text cannot be decoded + * + * @exception IllegalStateException + * if {@link #getInputStream} method has been called on this request + * + * @exception IOException + * if an input or output exception occurred + * + * @see javax.servlet.http.HttpServletRequest#getInputStream + */ + public abstract Reader getReader() throws IOException; + /** * The part of the request URL that comes after the server base. *

@@ -103,6 +144,10 @@ public abstract class RequestDetails { return myResourceName; } + public IRestfulResponse getResponse() { + return myResponse; + } + public RestOperationTypeEnum getRestOperationType() { return myRestOperationType; } @@ -113,14 +158,45 @@ public abstract class RequestDetails { public abstract IRestfulServerDefaults getServer(); + /** + * Returns the server base URL (with no trailing '/') for a given request + */ + public abstract String getServerBaseForRequest(); + public Map> getUnqualifiedToQualifiedNames() { return myUnqualifiedToQualifiedNames; } + /** + * Returns a map which can be used to hold any user specific data to pass it from one + * part of the request handling chain to another. Data in this map can use any key, although + * user code should try to use keys which are specific enough to avoid conflicts. + *

+ * A new map is created for each individual request that is handled by the server, + * so this map can be used (for example) to pass authorization details from an interceptor + * to the resource providers, or from an interceptor's {@link IServerInterceptor#incomingRequestPreHandled(RestOperationTypeEnum, ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails)} + * method to the {@link IServerInterceptor#outgoingResponse(RequestDetails, org.hl7.fhir.instance.model.api.IBaseResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)} + * method. + *

+ */ + public Map getUserData() { + if (myUserData == null) { + myUserData = new HashMap(); + } + return myUserData; + } + public boolean isRespondGzip() { return myRespondGzip; } + public final byte[] loadRequestContents() { + if (myRequestContents == null) { + myRequestContents = getByteStreamRequestContents(); + } + return myRequestContents; + } + public void setCompartmentName(String theCompartmentName) { myCompartmentName = theCompartmentName; } @@ -186,6 +262,10 @@ public abstract class RequestDetails { myRespondGzip = theRespondGzip; } + public void setResponse(IRestfulResponse theResponse) { + this.myResponse = theResponse; + } + public void setRestOperationType(RestOperationTypeEnum theRestOperationType) { myRestOperationType = theRestOperationType; } @@ -194,64 +274,4 @@ public abstract class RequestDetails { mySecondaryOperation = theSecondaryOperation; } - public IRestfulResponse getResponse() { - return myResponse; - } - - public void setResponse(IRestfulResponse theResponse) { - this.myResponse = theResponse; - } - - public abstract String getHeader(String name); - - public final byte[] loadRequestContents() { - if (myRequestContents == null) { - myRequestContents = getByteStreamRequestContents(); - } - return myRequestContents; - } - - protected abstract byte[] getByteStreamRequestContents(); - - public abstract List getHeaders(String name); - - /** - * Retrieves the body of the request as character data using a BufferedReader. The reader translates the - * character data according to the character encoding used on the body. Either this method or {@link #getInputStream} - * may be called to read the body, not both. - * - * @return a Reader containing the body of the request - * - * @exception UnsupportedEncodingException - * if the character set encoding used is not supported and the text cannot be decoded - * - * @exception IllegalStateException - * if {@link #getInputStream} method has been called on this request - * - * @exception IOException - * if an input or output exception occurred - * - * @see javax.servlet.http.HttpServletRequest#getInputStream - */ - public abstract Reader getReader() throws IOException; - - /** - * Retrieves the body of the request as binary data. Either this method or {@link #getReader} may be called to read - * the body, not both. - * - * @return a {@link InputStream} object containing the body of the request - * - * @exception IllegalStateException - * if the {@link #getReader} method has already been called for this request - * - * @exception IOException - * if an input or output exception occurred - */ - public abstract InputStream getInputStream() throws IOException; - - /** - * Returns the server base URL (with no trailing '/') for a given request - */ - public abstract String getServerBaseForRequest(); - } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java index 09c0ef8ae87..bfa6eabe1b0 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor; */ import java.io.IOException; +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -114,7 +115,16 @@ public interface IServerInterceptor { boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException; /** - * Invoked before an incoming request is processed + * Invoked before an incoming request is processed. Note that this method is called + * after the server has begin preparing the response to the incoming client request. + * As such, it is not able to supply a response to the incoming request in the way that + * {@link #incomingRequestPreHandled(RestOperationTypeEnum, ActionRequestDetails)} and + * {@link #incomingRequestPostProcessed(RequestDetails, HttpServletRequest, HttpServletResponse)} + * are. + *

+ * This method may however throw a subclass of {@link BaseServerResponseException}, and processing + * will be aborted with an appropriate error returned to the client. + *

* * @param theServletRequest * The incoming servlet request as provided by the servlet container @@ -151,15 +161,9 @@ public interface IServerInterceptor { * response back to the client * * @param theRequestDetails - * A bean containing details about the request that is about to be processed, including - * @param theResponseObject - * The actual object which is being streamed to the client as a response - * @param theServletRequest - * The incoming request - * @param theServletResponse - * The response. Note that interceptors may choose to provide a response (i.e. by calling - * {@link HttpServletResponse#getWriter()}) but in that case it is important to return false - * to indicate that the server itself should not also provide a response. + * A bean containing details about the request that is about to be processed, including details such as the + * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been + * pulled out of the {@link HttpServletRequest servlet request}. * @return Return true if processing should continue normally. This is generally the right thing to do. * If your interceptor is providing a response rather than letting HAPI handle the response normally, you * must return false. In this case, no further processing will occur and no further interceptors @@ -168,7 +172,7 @@ public interface IServerInterceptor { * This exception may be thrown to indicate that the interceptor has detected an unauthorized access * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client. */ - boolean outgoingResponse(RequestDetails theRequestDetails, Bundle theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; + boolean outgoingResponse(RequestDetails theRequestDetails); /** * This method is called after the server implementation method has been called, but before any attempt to stream the @@ -194,6 +198,30 @@ public interface IServerInterceptor { */ boolean outgoingResponse(RequestDetails theRequest, Bundle bundle); + /** + * This method is called after the server implementation method has been called, but before any attempt to stream the + * response back to the client + * + * @param theRequestDetails + * A bean containing details about the request that is about to be processed, including + * @param theResponseObject + * The actual object which is being streamed to the client as a response + * @param theServletRequest + * The incoming request + * @param theServletResponse + * The response. Note that interceptors may choose to provide a response (i.e. by calling + * {@link HttpServletResponse#getWriter()}) but in that case it is important to return false + * to indicate that the server itself should not also provide a response. + * @return Return true if processing should continue normally. This is generally the right thing to do. + * If your interceptor is providing a response rather than letting HAPI handle the response normally, you + * must return false. In this case, no further processing will occur and no further interceptors + * will be called. + * @throws AuthenticationException + * This exception may be thrown to indicate that the interceptor has detected an unauthorized access + * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client. + */ + boolean outgoingResponse(RequestDetails theRequestDetails, Bundle theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; + /** * This method is called after the server implementation method has been called, but before any attempt to stream the * response back to the client @@ -218,50 +246,6 @@ public interface IServerInterceptor { */ boolean outgoingResponse(RequestDetails theRequestDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; - /** - * This method is called after the server implementation method has been called, but before any attempt to stream the - * response back to the client - * - * @param theRequestDetails - * A bean containing details about the request that is about to be processed, including details such as the - * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been - * pulled out of the {@link HttpServletRequest servlet request}. - * @return Return true if processing should continue normally. This is generally the right thing to do. - * If your interceptor is providing a response rather than letting HAPI handle the response normally, you - * must return false. In this case, no further processing will occur and no further interceptors - * will be called. - * @throws AuthenticationException - * This exception may be thrown to indicate that the interceptor has detected an unauthorized access - * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client. - */ - boolean outgoingResponse(RequestDetails theRequestDetails); - - /** - * This method is called after the server implementation method has been called, but before any attempt to stream the - * response back to the client - * - * @param theRequestDetails - * A bean containing details about the request that is about to be processed, including details such as the - * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been - * pulled out of the {@link HttpServletRequest servlet request}. - * @param theResponseObject - * The actual object which is being streamed to the client as a response - * @param theServletRequest - * The incoming request - * @param theServletResponse - * The response. Note that interceptors may choose to provide a response (i.e. by calling - * {@link HttpServletResponse#getWriter()}) but in that case it is important to return false - * to indicate that the server itself should not also provide a response. - * @return Return true if processing should continue normally. This is generally the right thing to do. - * If your interceptor is providing a response rather than letting HAPI handle the response normally, you - * must return false. In this case, no further processing will occur and no further interceptors - * will be called. - * @throws AuthenticationException - * This exception may be thrown to indicate that the interceptor has detected an unauthorized access - * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client. - */ - boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; - /** * This method is called after the server implementation method has been called, but before any attempt to stream the * response back to the client @@ -306,7 +290,7 @@ public interface IServerInterceptor { * This exception may be thrown to indicate that the interceptor has detected an unauthorized access * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client. */ - boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; + boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; /** * This method is called after the server implementation method has been called, but before any attempt to stream the @@ -328,6 +312,32 @@ public interface IServerInterceptor { */ boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject); + /** + * This method is called after the server implementation method has been called, but before any attempt to stream the + * response back to the client + * + * @param theRequestDetails + * A bean containing details about the request that is about to be processed, including details such as the + * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been + * pulled out of the {@link HttpServletRequest servlet request}. + * @param theResponseObject + * The actual object which is being streamed to the client as a response + * @param theServletRequest + * The incoming request + * @param theServletResponse + * The response. Note that interceptors may choose to provide a response (i.e. by calling + * {@link HttpServletResponse#getWriter()}) but in that case it is important to return false + * to indicate that the server itself should not also provide a response. + * @return Return true if processing should continue normally. This is generally the right thing to do. + * If your interceptor is providing a response rather than letting HAPI handle the response normally, you + * must return false. In this case, no further processing will occur and no further interceptors + * will be called. + * @throws AuthenticationException + * This exception may be thrown to indicate that the interceptor has detected an unauthorized access + * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client. + */ + boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException; + /** * This method is called upon any exception being thrown within the server's request processing code. This includes * any exceptions thrown within resource provider methods (e.g. {@link Search} and {@link Read} methods) as well as @@ -353,33 +363,35 @@ public interface IServerInterceptor { BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException; public static class ActionRequestDetails { + private final FhirContext myContext; private final IIdType myId; - private boolean myLocked = false; + private RequestDetails myRequestDetails; private IBaseResource myResource; private final String myResourceType; - private final FhirContext myContext; - public ActionRequestDetails(IIdType theId, String theResourceType, FhirContext theContext) { + public ActionRequestDetails(IIdType theId, String theResourceType, FhirContext theContext, RequestDetails theRequestDetails) { myId = theId; myResourceType = theResourceType; myContext = theContext; + myRequestDetails = theRequestDetails; + } + + public ActionRequestDetails(IIdType theId, String theResourceType, IBaseResource theResource, FhirContext theContext, RequestDetails theRequestDetails) { + this(theId, theResourceType, theContext, theRequestDetails); + myResource = theResource; } public ActionRequestDetails(RequestDetails theRequestDetails) { myId = theRequestDetails.getId(); myResourceType = theRequestDetails.getResourceName(); myContext = theRequestDetails.getServer().getFhirContext(); + myRequestDetails = theRequestDetails; } public FhirContext getContext() { return myContext; } - public ActionRequestDetails(IIdType theId, String theResourceType, IBaseResource theResource, FhirContext theContext) { - this(theId, theResourceType, theContext); - myResource = theResource; - } - /** * Returns the ID of the incoming request (typically this is from the request URL) */ @@ -409,25 +421,19 @@ public interface IServerInterceptor { } /** - * Prevent any further changes to this object + * Returns the same map which was */ - public void lock() { - myLocked = true; + public Map getUserData() { + return myRequestDetails.getUserData(); } /** * This method should not be called by client code */ public void setResource(IBaseResource theObject) { - validateNotLocked(); myResource = theObject; } - private void validateNotLocked() { - if (myLocked) { - throw new IllegalStateException("Values on this object may not be changed"); - } - } } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 5224012fed5..0f49af83dba 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -123,6 +123,7 @@ import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.method.MethodUtil; import ca.uhn.fhir.rest.method.QualifiedParamList; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; @@ -1362,19 +1363,19 @@ public abstract class BaseHapiFhirDao implements IDao { } } - protected ResourceTable updateEntity(final IResource theResource, ResourceTable entity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, Date theUpdateTime) { - return updateEntity(theResource, entity, theUpdateHistory, theDeletedTimestampOrNull, true, true, theUpdateTime); + protected ResourceTable updateEntity(final IResource theResource, ResourceTable entity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, Date theUpdateTime, RequestDetails theRequestDetails) { + return updateEntity(theResource, entity, theUpdateHistory, theDeletedTimestampOrNull, true, true, theUpdateTime, theRequestDetails); } @SuppressWarnings("unchecked") - protected ResourceTable updateEntity(final IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) { + protected ResourceTable updateEntity(final IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHistory, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, RequestDetails theRequestDetails) { /* * This should be the very first thing.. */ if (theResource != null) { if (thePerformIndexing) { - validateResourceForStorage((T) theResource, theEntity); + validateResourceForStorage((T) theResource, theEntity, theRequestDetails); } String resourceType = myContext.getResourceDefinition(theResource).getName(); if (isNotBlank(theEntity.getResourceType()) && !theEntity.getResourceType().equals(resourceType)) { @@ -1663,8 +1664,9 @@ public abstract class BaseHapiFhirDao implements IDao { * The resource that is about to be persisted * @param theEntityToSave * TODO + * @param theRequestDetails TODO */ - protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave) { + protected void validateResourceForStorage(T theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) { Object tag = null; if (theResource instanceof IResource) { IResource res = (IResource) theResource; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index f0946330245..728243c432b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -75,6 +75,7 @@ import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.IBundleProvider; @@ -142,17 +143,17 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public DaoMethodOutcome create(final T theResource) { - return create(theResource, null, true); + public DaoMethodOutcome create(final T theResource, RequestDetails theRequestDetails) { + return create(theResource, null, true, theRequestDetails); } @Override - public DaoMethodOutcome create(final T theResource, String theIfNoneExist) { - return create(theResource, theIfNoneExist, true); + public DaoMethodOutcome create(final T theResource, String theIfNoneExist, RequestDetails theRequestDetails) { + return create(theResource, theIfNoneExist, true, theRequestDetails); } @Override - public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing) { + public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing, RequestDetails theRequestDetails) { if (isNotBlank(theResource.getIdElement().getIdPart())) { if (getContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) { if (theResource.getIdElement().isIdPartValidLong()) { @@ -165,7 +166,7 @@ public abstract class BaseHapiFhirResourceDao extends B } } - return doCreate(theResource, theIfNoneExist, thePerformIndexing, new Date()); + return doCreate(theResource, theIfNoneExist, thePerformIndexing, new Date(), theRequestDetails); } public IBaseOperationOutcome createErrorOperationOutcome(String theMessage, String theCode) { @@ -179,11 +180,11 @@ public abstract class BaseHapiFhirResourceDao extends B protected abstract IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode); @Override - public DaoMethodOutcome delete(IIdType theId) { + public DaoMethodOutcome delete(IIdType theId, RequestDetails theRequestDetails) { List deleteConflicts = new ArrayList(); StopWatch w = new StopWatch(); - ResourceTable savedEntity = delete(theId, deleteConflicts); + ResourceTable savedEntity = delete(theId, deleteConflicts, theRequestDetails); validateDeleteConflictsEmptyOrThrowException(deleteConflicts); @@ -192,7 +193,7 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public ResourceTable delete(IIdType theId, List deleteConflicts) { + public ResourceTable delete(IIdType theId, List deleteConflicts, RequestDetails theRequestDetails) { if (theId == null || !theId.hasIdPart()) { throw new InvalidRequestException("Can not perform delete, no ID provided"); } @@ -204,11 +205,11 @@ public abstract class BaseHapiFhirResourceDao extends B validateOkToDelete(deleteConflicts, entity); // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, theId.getResourceType(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, theId.getResourceType(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); Date updateTime = new Date(); - ResourceTable savedEntity = updateEntity(null, entity, true, updateTime, updateTime); + ResourceTable savedEntity = updateEntity(null, entity, true, updateTime, updateTime, theRequestDetails); // Notify JPA interceptors for (IServerInterceptor next : getConfig().getInterceptors()) { @@ -220,11 +221,11 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public DaoMethodOutcome deleteByUrl(String theUrl) { + public DaoMethodOutcome deleteByUrl(String theUrl, RequestDetails theRequestDetails) { StopWatch w = new StopWatch(); List deleteConflicts = new ArrayList(); - List deletedResources = deleteByUrl(theUrl, deleteConflicts); + List deletedResources = deleteByUrl(theUrl, deleteConflicts, theRequestDetails); validateDeleteConflictsEmptyOrThrowException(deleteConflicts); @@ -237,7 +238,7 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public List deleteByUrl(String theUrl, List deleteConflicts) { + public List deleteByUrl(String theUrl, List deleteConflicts, RequestDetails theRequestDetails) { Set resource = processMatchUrl(theUrl, myResourceType); if (resource.size() > 1) { if (myDaoConfig.isAllowMultipleDelete() == false) { @@ -254,12 +255,12 @@ public abstract class BaseHapiFhirResourceDao extends B // Notify interceptors IdDt idToDelete = entity.getIdDt(); - ActionRequestDetails requestDetails = new ActionRequestDetails(idToDelete, idToDelete.getResourceType(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(idToDelete, idToDelete.getResourceType(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); // Perform delete Date updateTime = new Date(); - updateEntity(null, entity, true, updateTime, updateTime); + updateEntity(null, entity, true, updateTime, updateTime, theRequestDetails); // Notify JPA interceptors for (IServerInterceptor next : getConfig().getInterceptors()) { @@ -273,7 +274,7 @@ public abstract class BaseHapiFhirResourceDao extends B return retVal; } - private DaoMethodOutcome doCreate(T theResource, String theIfNoneExist, boolean thePerformIndexing, Date theUpdateTime) { + private DaoMethodOutcome doCreate(T theResource, String theIfNoneExist, boolean thePerformIndexing, Date theUpdateTime, RequestDetails theRequestDetails) { StopWatch w = new StopWatch(); preProcessResourceForStorage(theResource); @@ -311,11 +312,11 @@ public abstract class BaseHapiFhirResourceDao extends B } // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theResource.getIdElement(), toResourceName(theResource), theResource, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails); // Perform actual DB update - updateEntity(theResource, entity, false, null, thePerformIndexing, true, theUpdateTime); + updateEntity(theResource, entity, false, null, thePerformIndexing, true, theUpdateTime, theRequestDetails); // Notify JPA interceptors for (IServerInterceptor next : getConfig().getInterceptors()) { @@ -334,9 +335,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public TagList getAllResourceTags() { + public TagList getAllResourceTags(RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.GET_TAGS, requestDetails); StopWatch w = new StopWatch(); @@ -357,9 +358,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public TagList getTags(IIdType theResourceId) { + public TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, null, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, null, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.GET_TAGS, requestDetails); StopWatch w = new StopWatch(); @@ -369,9 +370,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public IBundleProvider history(Date theSince) { + public IBundleProvider history(Date theSince, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.HISTORY_SYSTEM, requestDetails); StopWatch w = new StopWatch(); @@ -381,9 +382,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public IBundleProvider history(final IIdType theId, final Date theSince) { + public IBundleProvider history(final IIdType theId, final Date theSince, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.HISTORY_INSTANCE, requestDetails); final InstantDt end = createHistoryToTimestamp(); @@ -496,9 +497,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public IBundleProvider history(Long theId, Date theSince) { + public IBundleProvider history(Long theId, Date theSince, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.HISTORY_TYPE, requestDetails); StopWatch w = new StopWatch(); @@ -508,9 +509,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public MT metaAddOperation(IIdType theResourceId, MT theMetaAdd) { + public MT metaAddOperation(IIdType theResourceId, MT theMetaAdd, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.META_ADD, requestDetails); StopWatch w = new StopWatch(); @@ -548,7 +549,7 @@ public abstract class BaseHapiFhirResourceDao extends B ourLog.info("Processed metaAddOperation on {} in {}ms", new Object[] { theResourceId, w.getMillisAndRestart() }); @SuppressWarnings("unchecked") - MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId); + MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId, theRequestDetails); return retVal; } @@ -635,9 +636,9 @@ public abstract class BaseHapiFhirResourceDao extends B // } @Override - public MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel) { + public MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theResourceId, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.META_DELETE, requestDetails); StopWatch w = new StopWatch(); @@ -671,14 +672,14 @@ public abstract class BaseHapiFhirResourceDao extends B ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[] { theResourceId.getValue(), w.getMillisAndRestart() }); @SuppressWarnings("unchecked") - MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId); + MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId, theRequestDetails); return retVal; } @Override - public MT metaGetOperation(Class theType) { + public MT metaGetOperation(Class theType, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t WHERE t.myResourceType = :res_type)"; @@ -715,9 +716,9 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public MT metaGetOperation(Class theType, IIdType theId) { + public MT metaGetOperation(Class theType, IIdType theId, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); Set tagDefs = new HashSet(); @@ -775,11 +776,11 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public T read(IIdType theId) { + public T read(IIdType theId, RequestDetails theRequestDetails) { validateResourceTypeAndThrowIllegalArgumentException(theId); // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails); RestOperationTypeEnum operationType = theId.hasVersionIdPart() ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ; notifyInterceptors(operationType, requestDetails); @@ -864,14 +865,14 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public void reindex(T theResource, ResourceTable theEntity) { - updateEntity(theResource, theEntity, false, null, true, false, theEntity.getUpdatedDate()); + public void reindex(T theResource, ResourceTable theEntity, RequestDetails theRequestDetails) { + updateEntity(theResource, theEntity, false, null, true, false, theEntity.getUpdatedDate(), theRequestDetails); } @Override - public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm) { + public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails); StopWatch w = new StopWatch(); @@ -912,7 +913,7 @@ public abstract class BaseHapiFhirResourceDao extends B @Override public IBundleProvider search(final SearchParameterMap theParams) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theParams.getRequestDetails()); notifyInterceptors(RestOperationTypeEnum.SEARCH_TYPE, requestDetails); SearchBuilder builder = new SearchBuilder(getContext(), myEntityManager, myPlatformTransactionManager, mySearchDao, mySearchResultDao, this, myResourceIndexedSearchParamUriDao); @@ -1005,17 +1006,17 @@ public abstract class BaseHapiFhirResourceDao extends B } @Override - public DaoMethodOutcome update(T theResource) { - return update(theResource, null); + public DaoMethodOutcome update(T theResource, RequestDetails theRequestDetails) { + return update(theResource, null, theRequestDetails); } @Override - public DaoMethodOutcome update(T theResource, String theMatchUrl) { - return update(theResource, theMatchUrl, true); + public DaoMethodOutcome update(T theResource, String theMatchUrl, RequestDetails theRequestDetails) { + return update(theResource, theMatchUrl, true, theRequestDetails); } @Override - public DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing) { + public DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing, RequestDetails theRequestDetails) { StopWatch w = new StopWatch(); preProcessResourceForStorage(theResource); @@ -1033,7 +1034,7 @@ public abstract class BaseHapiFhirResourceDao extends B entity = myEntityManager.find(ResourceTable.class, pid); resourceId = entity.getIdDt(); } else { - return create(theResource, null, thePerformIndexing); + return create(theResource, null, thePerformIndexing, theRequestDetails); } } else { resourceId = theResource.getIdElement(); @@ -1046,7 +1047,7 @@ public abstract class BaseHapiFhirResourceDao extends B if (resourceId.isIdPartValidLong()) { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart())); } - return doCreate(theResource, null, thePerformIndexing, new Date()); + return doCreate(theResource, null, thePerformIndexing, new Date(), theRequestDetails); } } @@ -1059,11 +1060,11 @@ public abstract class BaseHapiFhirResourceDao extends B } // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(resourceId, getResourceName(), theResource, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(resourceId, getResourceName(), theResource, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.UPDATE, requestDetails); // Perform update - ResourceTable savedEntity = updateEntity(theResource, entity, true, null, thePerformIndexing, true, new Date()); + ResourceTable savedEntity = updateEntity(theResource, entity, true, null, thePerformIndexing, true, new Date(), theRequestDetails); // Notify JPA interceptors for (IServerInterceptor next : getConfig().getInterceptors()) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java index f41b5ef034a..234703684fa 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java @@ -49,6 +49,7 @@ import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; @@ -62,15 +63,15 @@ public abstract class BaseHapiFhirSystemDao extends BaseHapiFhirDao() { @@ -102,7 +103,7 @@ public abstract class BaseHapiFhirSystemDao extends BaseHapiFhirDao extends BaseHapiFhirDao extends BaseHapiFhirDao extends BaseHapiFhirDao extends BaseHapiFhirResou } @Override - public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) { + public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) { throw new UnsupportedOperationException(); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java index 356574f28a3..313e9b36513 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java @@ -52,6 +52,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; @@ -98,8 +99,8 @@ public class FhirResourceDaoDstu2 extends BaseHapiFhirResou } @Override - public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) { - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext()); + public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) { + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails); if (theMode == ValidationModeEnum.DELETE) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java index d91cd02a7e4..313354c7991 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java @@ -32,6 +32,7 @@ import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringParam; @@ -66,18 +67,18 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2im } @Override - public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails); return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative); } @Override - public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails); return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java index 7ecc8ac8a84..2685aacb398 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java @@ -35,6 +35,7 @@ import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; import ca.uhn.fhir.model.dstu2.resource.Questionnaire; import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse; import ca.uhn.fhir.model.dstu2.resource.ValueSet; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.validation.FhirValidator; @@ -63,8 +64,8 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs } @Override - protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave) { - super.validateResourceForStorage(theResource, theEntityToSave); + protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) { + super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails); if (!myValidateResponses) { return; } @@ -79,7 +80,7 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs val.setValidateAgainstStandardSchematron(false); FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator(); - module.setResourceLoader(new JpaResourceLoader()); + module.setResourceLoader(new JpaResourceLoader(theRequestDetails)); val.registerValidatorModule(module); ValidationResult result = val.validateWithResult(myRefImplCtx.newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(qa))); @@ -91,6 +92,12 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs public class JpaResourceLoader implements IResourceLoader { + private RequestDetails myRequestDetails; + + public JpaResourceLoader(RequestDetails theRequestDetails) { + myRequestDetails = theRequestDetails; + } + @Override public T load(Class theType, IIdType theId) throws ResourceNotFoundException { @@ -100,7 +107,7 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs */ if ("ValueSet".equals(theType.getSimpleName())) { IFhirResourceDao dao = getDao(ValueSet.class); - ValueSet in = dao.read(theId); + ValueSet in = dao.read(theId, myRequestDetails); String encoded = getContext().newJsonParser().encodeResourceToString(in); // TODO: this is temporary until structures-dstu2 catches up to structures-hl7org.dstu2 @@ -109,7 +116,7 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs return myRefImplCtx.newJsonParser().parseResource(theType, encoded); } else if ("Questionnaire".equals(theType.getSimpleName())) { IFhirResourceDao dao = getDao(Questionnaire.class); - Questionnaire vs = dao.read(theId); + Questionnaire vs = dao.read(theId, myRequestDetails); return myRefImplCtx.newJsonParser().parseResource(theType, getContext().newJsonParser().encodeResourceToString(vs)); } else { // Should not happen, validator will only ask for these two diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu2.java index 8aedacf6397..b4c053e4d07 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSearchParameterDstu2.java @@ -27,6 +27,8 @@ import org.springframework.scheduling.annotation.Scheduled; import ca.uhn.fhir.model.dstu2.composite.MetaDt; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.SearchParameter; +import ca.uhn.fhir.rest.method.RequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2implements IFhirResourceDaoSearchParameter { @@ -46,9 +48,10 @@ public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2 0; i++) { - count = mySystemDao.performReindexingPass(100); + count = mySystemDao.performReindexingPass(100, requestDetails); try { Thread.sleep(DateUtils.MILLIS_PER_SECOND); } catch (InterruptedException e) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java index 8e2e2b44d6d..9d0ffbbeb32 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoSubscriptionDstu2.java @@ -60,11 +60,13 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2implements IFhirResourceDaoSubscription { @@ -250,7 +252,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2() { @Override public Void doInTransaction(TransactionStatus theStatus) { - delete(subscriptionId); + delete(subscriptionId, new ServletRequestDetails()); return null; } }); @@ -259,8 +261,8 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2 } @Override - public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, CodingDt theCoding) { + public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, CodingDt theCoding, RequestDetails theRequestDetails) { boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode()); boolean haveCode = theCode != null && theCode.isEmpty() == false; boolean haveSystem = theSystem != null && theSystem.isEmpty() == false; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1.java index d575b8e5e76..ce5bdb9ebe3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1.java @@ -54,7 +54,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao, M private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu1.class); @Override - public MetaDt metaGetOperation() { + public MetaDt metaGetOperation(RequestDetails theRequestDetails) { throw new NotImplementedOperationException("meta not supported in DSTU1"); } @@ -64,7 +64,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao, M ourLog.info("Beginning transaction with {} resources", theResources.size()); // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails); long start = System.currentTimeMillis(); @@ -270,7 +270,7 @@ public class FhirSystemDaoDstu1 extends BaseHapiFhirSystemDao, M ResourceMetadataKeyEnum.DELETED_AT.put(resource, new InstantDt(deletedTimestampOrNull)); } - updateEntity(resource, table, table.getId() != null, deletedTimestampOrNull, updateTime); + updateEntity(resource, table, table.getId() != null, deletedTimestampOrNull, updateTime, theRequestDetails); } long delay = System.currentTimeMillis() - start; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java index b67c83c5643..c835c22d289 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java @@ -198,9 +198,9 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { } @Override - public MetaDt metaGetOperation() { + public MetaDt metaGetOperation(RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)"; @@ -259,7 +259,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { @Transactional(propagation = Propagation.REQUIRED) @Override public Bundle transaction(RequestDetails theRequestDetails, Bundle theRequest) { - ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails); String actionName = "Transaction"; @@ -379,7 +379,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { IFhirResourceDao resourceDao = getDaoOrThrowException(res.getClass()); res.setId((String) null); DaoMethodOutcome outcome; - outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false); + outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false, theRequestDetails); handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res); break; } @@ -390,12 +390,12 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { ca.uhn.fhir.jpa.dao.IFhirResourceDao dao = toDao(parts, verb.getCode(), url); int status = Constants.STATUS_HTTP_204_NO_CONTENT; if (parts.getResourceId() != null) { - ResourceTable deleted = dao.delete(new IdDt(parts.getResourceType(), parts.getResourceId()), deleteConflicts); + ResourceTable deleted = dao.delete(new IdDt(parts.getResourceType(), parts.getResourceId()), deleteConflicts, theRequestDetails); if (deleted != null) { deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless()); } } else { - List allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts); + List allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts, theRequestDetails); for (ResourceTable deleted : allDeleted) { deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless()); } @@ -419,10 +419,10 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { UrlParts parts = UrlUtil.parseUrl(url); if (isNotBlank(parts.getResourceId())) { res.setId(new IdDt(parts.getResourceType(), parts.getResourceId())); - outcome = resourceDao.update(res, null, false); + outcome = resourceDao.update(res, null, false, theRequestDetails); } else { res.setId((String) null); - outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false); + outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false, theRequestDetails); } handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res); @@ -471,7 +471,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao { InstantDt deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get(nextResource); Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null; - updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime); + updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime, theRequestDetails); } myEntityManager.flush(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDao.java index 41cf942ab00..adef7dcc5aa 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDao.java @@ -39,6 +39,7 @@ import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.IBundleProvider; @@ -48,82 +49,92 @@ public interface IFhirResourceDao extends IDao { void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel); - DaoMethodOutcome create(T theResource); + DaoMethodOutcome create(T theResource, RequestDetails theRequestDetails); - DaoMethodOutcome create(T theResource, String theIfNoneExist); + DaoMethodOutcome create(T theResource, String theIfNoneExist, RequestDetails theRequestDetails); /** * @param thePerformIndexing * Use with caution! If you set this to false, you need to manually perform indexing or your resources * won't be indexed and searches won't work. + * @param theRequestDetails TODO */ - DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing); + DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing, RequestDetails theRequestDetails); /** * This method throws an exception if there are delete conflicts + * @param theRequestDetails TODO */ - DaoMethodOutcome delete(IIdType theResource); + DaoMethodOutcome delete(IIdType theResource, RequestDetails theRequestDetails); /** * This method does not throw an exception if there are delete conflicts, but populates them * in the provided list + * @param theRequestDetails TODO */ - ResourceTable delete(IIdType theResource, List theDeleteConflictsListToPopulate); + ResourceTable delete(IIdType theResource, List theDeleteConflictsListToPopulate, RequestDetails theRequestDetails); /** * This method throws an exception if there are delete conflicts + * @param theRequestDetails TODO */ - DaoMethodOutcome deleteByUrl(String theString); + DaoMethodOutcome deleteByUrl(String theString, RequestDetails theRequestDetails); /** * This method does not throw an exception if there are delete conflicts, but populates them * in the provided list + * @param theRequestDetails TODO * @return */ - List deleteByUrl(String theUrl, List theDeleteConflictsListToPopulate); + List deleteByUrl(String theUrl, List theDeleteConflictsListToPopulate, RequestDetails theRequestDetails); - TagList getAllResourceTags(); + TagList getAllResourceTags(RequestDetails theRequestDetails); Class getResourceType(); - TagList getTags(IIdType theResourceId); + TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails); - IBundleProvider history(Date theSince); + IBundleProvider history(Date theSince, RequestDetails theRequestDetails); - IBundleProvider history(IIdType theId, Date theSince); + IBundleProvider history(IIdType theId, Date theSince, RequestDetails theRequestDetails); - IBundleProvider history(Long theId, Date theSince); + IBundleProvider history(Long theId, Date theSince, RequestDetails theRequestDetails); /** * Not supported in DSTU1! + * @param theRequestDetails TODO */ - MT metaAddOperation(IIdType theId1, MT theMetaAdd); + MT metaAddOperation(IIdType theId1, MT theMetaAdd, RequestDetails theRequestDetails); /** * Not supported in DSTU1! + * @param theRequestDetails TODO */ - MT metaDeleteOperation(IIdType theId1, MT theMetaDel); + MT metaDeleteOperation(IIdType theId1, MT theMetaDel, RequestDetails theRequestDetails); /** * Not supported in DSTU1! + * @param theRequestDetails TODO */ - MT metaGetOperation(Class theType); + MT metaGetOperation(Class theType, RequestDetails theRequestDetails); /** * Not supported in DSTU1! + * @param theRequestDetails TODO */ - MT metaGetOperation(Class theType, IIdType theId); + MT metaGetOperation(Class theType, IIdType theId, RequestDetails theRequestDetails); Set processMatchUrl(String theMatchUrl); /** * * @param theId + * @param theRequestDetails TODO * @return * @throws ResourceNotFoundException * If the ID is not known to the server */ - T read(IIdType theId); + T read(IIdType theId, RequestDetails theRequestDetails); BaseHasResource readEntity(IIdType theId); @@ -137,10 +148,11 @@ public interface IFhirResourceDao extends IDao { /** * Updates index tables associated with the given resource. Does not create a new * version or update the resource's update time. + * @param theRequestDetails TODO */ - void reindex(T theResource, ResourceTable theEntity); + void reindex(T theResource, ResourceTable theEntity, RequestDetails theRequestDetails); - void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm); + void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, RequestDetails theRequestDetails); IBundleProvider search(Map theParams); @@ -154,21 +166,23 @@ public interface IFhirResourceDao extends IDao { Set searchForIdsWithAndOr(SearchParameterMap theParams, Collection theInitialPids, DateRangeParam theLastUpdated); - DaoMethodOutcome update(T theResource); + DaoMethodOutcome update(T theResource, RequestDetails theRequestDetails); - DaoMethodOutcome update(T theResource, String theMatchUrl); + DaoMethodOutcome update(T theResource, String theMatchUrl, RequestDetails theRequestDetails); /** * @param thePerformIndexing * Use with caution! If you set this to false, you need to manually perform indexing or your resources * won't be indexed and searches won't work. + * @param theRequestDetails TODO */ - DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing); + DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing, RequestDetails theRequestDetails); /** * Not supported in DSTU1! + * @param theRequestDetails TODO */ - MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile); + MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails); // /** // * Invoke the everything operation diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java index c683b45660e..8b3cf79d00f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java @@ -27,14 +27,15 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.server.IBundleProvider; public interface IFhirResourceDaoPatient extends IFhirResourceDao { - IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative); + IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails); - IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative); + IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java index c82bca8ff82..253b811465e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoValueSet.java @@ -24,6 +24,8 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; +import ca.uhn.fhir.rest.method.RequestDetails; + public interface IFhirResourceDaoValueSet extends IFhirResourceDao { T expand(IIdType theId, String theFilter); @@ -32,7 +34,7 @@ public interface IFhirResourceDaoValueSet exten T expandByIdentifier(String theUri, String theFilter); - LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, CD theCoding); + LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, CD theCoding, RequestDetails theRequestDetails); ValidateCodeResult validateCode(IPrimitiveType theValueSetIdentifier, IIdType theId, IPrimitiveType theCode, IPrimitiveType theSystem, IPrimitiveType theDisplay, CD theCoding, CC theCodeableConcept); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java index 7a65265919f..22992c07d30 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java @@ -35,14 +35,15 @@ public interface IFhirSystemDao extends IDao { /** * Use with caution! This deletes everything!! + * @param theRequestDetails TODO */ - void deleteAllTagsOnServer(); + void deleteAllTagsOnServer(RequestDetails theRequestDetails); - TagList getAllTags(); + TagList getAllTags(RequestDetails theRequestDetails); Map getResourceCounts(); - IBundleProvider history(Date theDate); + IBundleProvider history(Date theDate, RequestDetails theRequestDetails); /** * Marks all indexes as needing fresh indexing @@ -53,10 +54,11 @@ public interface IFhirSystemDao extends IDao { /** * Not supported for DSTU1 + * @param theRequestDetails TODO */ - MT metaGetOperation(); + MT metaGetOperation(RequestDetails theRequestDetails); - int performReindexingPass(Integer theCount); + int performReindexingPass(Integer theCount, RequestDetails theRequestDetails); T transaction(RequestDetails theRequestDetails, T theResources); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java index 99d75ee7263..89591800d9f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java @@ -34,6 +34,7 @@ import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.Constants; @@ -45,6 +46,7 @@ public class SearchParameterMap extends LinkedHashMap myIncludes; private DateRangeParam myLastUpdated; + private RequestDetails myRequestDetails; private Set myRevIncludes; private SortSpec mySort; @@ -101,6 +103,10 @@ public class SearchParameterMap extends LinkedHashMap getIncludes() { if (myIncludes == null) { myIncludes = new HashSet(); @@ -112,6 +118,10 @@ public class SearchParameterMap extends LinkedHashMap getRevIncludes() { if (myRevIncludes == null) { myRevIncludes = new HashSet(); @@ -123,10 +133,6 @@ public class SearchParameterMap extends LinkedHashMap theRevIncludes) { myRevIncludes = theRevIncludes; } @@ -164,36 +174,36 @@ public class SearchParameterMap extends LinkedHashMap extends BaseHapiFhirRe } @Override - public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) { - ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext()); + public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) { + ActionRequestDetails requestDetails = new ActionRequestDetails(theId, null, theResource, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails); if (theMode == ValidationModeEnum.DELETE) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoPatientDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoPatientDstu3.java index 3563eda56f7..ac54d9d93d3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoPatientDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoPatientDstu3.java @@ -35,6 +35,7 @@ import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringParam; @@ -69,18 +70,18 @@ public class FhirResourceDaoPatientDstu3 extends FhirResourceDaoDstu3im } @Override - public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE, requestDetails); return doEverythingOperation(theId, theCount, theLastUpdated, theSort, theContent, theNarrative); } @Override - public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative) { + public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, IPrimitiveType theCount, DateRangeParam theLastUpdated, SortSpec theSort, StringAndListParam theContent, StringAndListParam theNarrative, RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, getResourceName(), getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, requestDetails); return doEverythingOperation(null, theCount, theLastUpdated, theSort, theContent, theNarrative); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoQuestionnaireResponseDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoQuestionnaireResponseDstu3.java index 0dccafd8a2f..4d74c31060f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoQuestionnaireResponseDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoQuestionnaireResponseDstu3.java @@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.entity.ResourceTable; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.validation.FhirValidator; @@ -64,8 +65,8 @@ public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDs } @Override - protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave) { - super.validateResourceForStorage(theResource, theEntityToSave); + protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) { + super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails); if (!myValidateResponses) { return; } @@ -89,6 +90,13 @@ public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDs public class JpaResourceLoader implements IResourceLoader { + private RequestDetails myRequestDetails; + + public JpaResourceLoader(RequestDetails theRequestDetails) { + super(); + myRequestDetails = theRequestDetails; + } + @Override public T load(Class theType, IIdType theId) throws ResourceNotFoundException { @@ -98,11 +106,11 @@ public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDs */ if ("ValueSet".equals(theType.getSimpleName())) { IFhirResourceDao dao = getDao(ValueSet.class); - ValueSet in = dao.read(theId); + ValueSet in = dao.read(theId, myRequestDetails); return (T) in; } else if ("Questionnaire".equals(theType.getSimpleName())) { IFhirResourceDao dao = getDao(Questionnaire.class); - Questionnaire vs = dao.read(theId); + Questionnaire vs = dao.read(theId, myRequestDetails); return (T) vs; } else { // Should not happen, validator will only ask for these two diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java index 24cc8493071..b6490c883c4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSearchParameterDstu3.java @@ -29,6 +29,8 @@ import org.springframework.scheduling.annotation.Scheduled; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSearchParameter; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; +import ca.uhn.fhir.rest.method.RequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoSearchParameterDstu3 extends FhirResourceDaoDstu3implements IFhirResourceDaoSearchParameter { @@ -48,9 +50,10 @@ public class FhirResourceDaoSearchParameterDstu3 extends FhirResourceDaoDstu3 0; i++) { - count = mySystemDao.performReindexingPass(100); + count = mySystemDao.performReindexingPass(100, requestDetails); try { Thread.sleep(DateUtils.MILLIS_PER_SECOND); } catch (InterruptedException e) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSubscriptionDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSubscriptionDstu3.java index 6d20c954c38..a61288de7a9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSubscriptionDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoSubscriptionDstu3.java @@ -64,11 +64,13 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3implements IFhirResourceDaoSubscription { @@ -255,7 +257,7 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3() { @Override public Void doInTransaction(TransactionStatus theStatus) { - delete(subscriptionId); + delete(subscriptionId, new ServletRequestDetails()); return null; } }); @@ -264,8 +266,8 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3 } @Override - public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, Coding theCoding) { + public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult lookupCode(IPrimitiveType theCode, IPrimitiveType theSystem, Coding theCoding, RequestDetails theRequestDetails) { boolean haveCoding = theCoding != null && isNotBlank(theCoding.getSystem()) && isNotBlank(theCoding.getCode()); boolean haveCode = theCode != null && theCode.isEmpty() == false; boolean haveSystem = theSystem != null && theSystem.isEmpty() == false; @@ -349,7 +350,7 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3 List valueSetIds = findValueSetIdsContainingSystemAndCode(code, system); for (IIdType nextId : valueSetIds) { - ValueSet expansion = read(nextId); + ValueSet expansion = read(nextId, theRequestDetails); for (ConceptDefinitionComponent next : expansion.getCodeSystem().getConcept()) { if (code.equals(next.getCode())) { ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult retVal = new LookupCodeResult(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3.java index b057355237d..2e49a1d6f26 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3.java @@ -202,9 +202,9 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao { } @Override - public Meta metaGetOperation() { + public Meta metaGetOperation(RequestDetails theRequestDetails) { // Notify interceptors - ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, null, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t)"; @@ -263,7 +263,7 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao { @Transactional(propagation = Propagation.REQUIRED) @Override public Bundle transaction(RequestDetails theRequestDetails, Bundle theRequest) { - ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext()); + ActionRequestDetails requestDetails = new ActionRequestDetails(null, "Bundle", theRequest, getContext(), theRequestDetails); notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails); String actionName = "Transaction"; @@ -389,7 +389,7 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao { IFhirResourceDao resourceDao = getDaoOrThrowException(res.getClass()); res.setId((String) null); DaoMethodOutcome outcome; - outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false); + outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false, theRequestDetails); handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res); break; } @@ -400,12 +400,12 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao { ca.uhn.fhir.jpa.dao.IFhirResourceDao dao = toDao(parts, verb.toCode(), url); int status = Constants.STATUS_HTTP_204_NO_CONTENT; if (parts.getResourceId() != null) { - ResourceTable deleted = dao.delete(new IdType(parts.getResourceType(), parts.getResourceId()), deleteConflicts); + ResourceTable deleted = dao.delete(new IdType(parts.getResourceType(), parts.getResourceId()), deleteConflicts, theRequestDetails); if (deleted != null) { deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless()); } } else { - List allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts); + List allDeleted = dao.deleteByUrl(parts.getResourceType() + '?' + parts.getParams(), deleteConflicts, theRequestDetails); for (ResourceTable deleted : allDeleted) { deletedResources.add(deleted.getIdDt().toUnqualifiedVersionless()); } @@ -429,10 +429,10 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao { UrlParts parts = UrlUtil.parseUrl(url); if (isNotBlank(parts.getResourceId())) { res.setId(new IdType(parts.getResourceType(), parts.getResourceId())); - outcome = resourceDao.update(res, null, false); + outcome = resourceDao.update(res, null, false, theRequestDetails); } else { res.setId((String) null); - outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false); + outcome = resourceDao.update(res, parts.getResourceType() + '?' + parts.getParams(), false, theRequestDetails); } handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res); @@ -481,7 +481,7 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao { IPrimitiveType deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) nextResource); Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null; - updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime); + updateEntity(nextResource, nextOutcome.getEntity(), false, deletedTimestampOrNull, true, false, updateTime, theRequestDetails); } myEntityManager.flush(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProvider.java index 31ec6ec4bb3..bdaf0101308 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProvider.java @@ -35,6 +35,7 @@ import ca.uhn.fhir.rest.annotation.History; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Since; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.util.CoverageIgnore; @@ -57,20 +58,20 @@ public abstract class BaseJpaResourceProvider extends B } @History - public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theId, @Since Date theDate) { + public IBundleProvider getHistoryForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theId, @Since Date theDate, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.history(theId, theDate); + return myDao.history(theId, theDate, theRequestDetails); } finally { endRequest(theRequest); } } @History - public IBundleProvider getHistoryForResourceType(HttpServletRequest theRequest, @Since Date theDate) { + public IBundleProvider getHistoryForResourceType(HttpServletRequest theRequest, @Since Date theDate, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.history(theDate); + return myDao.history(theDate, theRequestDetails); } finally { endRequest(theRequest); } @@ -82,30 +83,30 @@ public abstract class BaseJpaResourceProvider extends B } @GetTags - public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId) { + public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.getTags(theResourceId); + return myDao.getTags(theResourceId, theRequestDetails); } finally { endRequest(theRequest); } } @GetTags - public TagList getTagsForResourceType(HttpServletRequest theRequest) { + public TagList getTagsForResourceType(HttpServletRequest theRequest, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.getAllResourceTags(); + return myDao.getAllResourceTags(theRequestDetails); } finally { endRequest(theRequest); } } @Read(version = true) - public T read(HttpServletRequest theRequest, @IdParam IIdType theId) { + public T read(HttpServletRequest theRequest, @IdParam IIdType theId, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.read(theId); + return myDao.read(theId, theRequestDetails); } finally { endRequest(theRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java index f4814b57cb9..b53db1a44dc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java @@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.Sort; import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringOrListParam; @@ -43,6 +44,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu /** * Patient/123/$everything + * @param theRequestDetails */ //@formatter:off @Operation(name = "everything", idempotent = true) @@ -70,13 +72,15 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu List theNarrative, @Sort - SortSpec theSortSpec + SortSpec theSortSpec, + + RequestDetails theRequestDetails ) { //@formatter:on startRequest(theServletRequest); try { - return ((IFhirResourceDaoPatient) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative)); + return ((IFhirResourceDaoPatient) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails); } finally { endRequest(theServletRequest); } @@ -84,6 +88,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu /** * /Patient/$everything + * @param theRequestDetails */ //@formatter:off @Operation(name = "everything", idempotent = true) @@ -108,13 +113,15 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu List theNarrative, @Sort - SortSpec theSortSpec + SortSpec theSortSpec, + + RequestDetails theRequestDetails ) { //@formatter:on startRequest(theServletRequest); try { - return ((IFhirResourceDaoPatient) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative)); + return ((IFhirResourceDaoPatient) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails); } finally { endRequest(theServletRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderValueSetDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderValueSetDstu2.java index 35f6637c41c..981840549f0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderValueSetDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderValueSetDstu2.java @@ -39,6 +39,7 @@ import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; @@ -113,14 +114,15 @@ public class BaseJpaResourceProviderValueSetDstu2 extends JpaResourceProviderDst HttpServletRequest theServletRequest, @OperationParam(name="code", min=0, max=1) CodeDt theCode, @OperationParam(name="system", min=0, max=1) UriDt theSystem, - @OperationParam(name="coding", min=0, max=1) CodingDt theCoding + @OperationParam(name="coding", min=0, max=1) CodingDt theCoding, + RequestDetails theRequestDetails ) { //@formatter:on startRequest(theServletRequest); try { IFhirResourceDaoValueSet dao = (IFhirResourceDaoValueSet) getDao(); - LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding); + LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding, theRequestDetails); if (result.isFound()==false) { throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]"); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaSystemProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaSystemProvider.java index fc317296365..007515a7591 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaSystemProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaSystemProvider.java @@ -31,6 +31,7 @@ import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.rest.annotation.GetTags; import ca.uhn.fhir.rest.annotation.History; import ca.uhn.fhir.rest.annotation.Since; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.IBundleProvider; public class BaseJpaSystemProvider extends BaseJpaProvider { @@ -47,10 +48,10 @@ public class BaseJpaSystemProvider extends BaseJpaProvider { } @History - public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate) { + public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.history(theDate); + return myDao.history(theDate, theRequestDetails); } finally { endRequest(theRequest); } @@ -61,10 +62,10 @@ public class BaseJpaSystemProvider extends BaseJpaProvider { } @GetTags - public TagList getAllTagsOnServer(HttpServletRequest theRequest) { + public TagList getAllTagsOnServer(HttpServletRequest theRequest, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return myDao.getAllTags(); + return myDao.getAllTags(theRequestDetails); } finally { endRequest(theRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu1.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu1.java index 97be3b195fc..96ac765518f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu1.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu1.java @@ -34,6 +34,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; public class JpaResourceProviderDstu1 extends BaseJpaResourceProvider { @@ -49,35 +50,35 @@ public class JpaResourceProviderDstu1 extends BaseJpaResour } @Create - public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource) { + public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return getDao().create(theResource); + return getDao().create(theResource, theRequestDetails); } finally { endRequest(theRequest); } } @Delete - public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource) { + public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, RequestDetails theRequestDetails) { startRequest(theRequest); try { - return getDao().delete(theResource); + return getDao().delete(theResource, theRequestDetails); } finally { endRequest(theRequest); } } @Update - public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId) { + public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, RequestDetails theRequestDetails) { startRequest(theRequest); try { theResource.setId(theId); - return getDao().update(theResource); + return getDao().update(theResource, theRequestDetails); } catch (ResourceNotFoundException e) { ourLog.info("Can't update resource with ID[" + theId.getValue() + "] because it doesn't exist, going to create it instead"); theResource.setId(theId); - return getDao().create(theResource); + return getDao().create(theResource, theRequestDetails); } finally { endRequest(theRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java index 6f12d33b1e0..131ab5bdbe5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java @@ -38,8 +38,10 @@ import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class JpaResourceProviderDstu2 extends BaseJpaResourceProvider { @@ -56,13 +58,13 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour } @Create - public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional) { + public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) { startRequest(theRequest); try { if (theConditional != null) { - return getDao().create(theResource, theConditional); + return getDao().create(theResource, theConditional, theRequestDetails); } else { - return getDao().create(theResource); + return getDao().create(theResource, theRequestDetails); } } finally { endRequest(theRequest); @@ -70,13 +72,13 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour } @Delete() - public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) { + public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional, RequestDetails theRequestDetails) { startRequest(theRequest); try { if (theConditional != null) { - return getDao().deleteByUrl(theConditional); + return getDao().deleteByUrl(theConditional, theRequestDetails); } else { - return getDao().delete(theResource); + return getDao().delete(theResource, theRequestDetails); } } finally { endRequest(theRequest); @@ -88,9 +90,9 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour @OperationParam(name="return", type=MetaDt.class) }) //@formatter:on - public Parameters meta() { + public Parameters meta(RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); - MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class); + MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theRequestDetails); parameters.addParameter().setName("return").setValue(metaGetOperation); return parameters; } @@ -100,9 +102,9 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour @OperationParam(name="return", type=MetaDt.class) }) //@formatter:on - public Parameters meta(@IdParam IdDt theId) { + public Parameters meta(@IdParam IdDt theId, RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); - MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theId); + MetaDt metaGetOperation = getDao().metaGetOperation(MetaDt.class, theId, theRequestDetails); parameters.addParameter().setName("return").setValue(metaGetOperation); return parameters; } @@ -112,12 +114,12 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour @OperationParam(name="return", type=MetaDt.class) }) //@formatter:on - public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) { + public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta, RequestDetails theRequestDetails) { if (theMeta == null) { throw new InvalidRequestException("Input contains no parameter with name 'meta'"); } Parameters parameters = new Parameters(); - MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta); + MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta, theRequestDetails); parameters.addParameter().setName("return").setValue(metaAddOperation); return parameters; } @@ -127,24 +129,24 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour @OperationParam(name="return", type=MetaDt.class) }) //@formatter:on - public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) { + public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta, RequestDetails theRequestDetails) { if (theMeta == null) { throw new InvalidRequestException("Input contains no parameter with name 'meta'"); } Parameters parameters = new Parameters(); - parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta)); + parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta, theRequestDetails)); return parameters; } @Update - public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, @ConditionalUrlParam String theConditional) { + public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdDt theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) { startRequest(theRequest); try { if (theConditional != null) { - return getDao().update(theResource, theConditional); + return getDao().update(theResource, theConditional, theRequestDetails); } else { theResource.setId(theId); - return getDao().update(theResource); + return getDao().update(theResource, theRequestDetails); } } finally { endRequest(theRequest); @@ -153,14 +155,14 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour @Validate public MethodOutcome validate(@ResourceParam T theResource, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode, - @Validate.Profile String theProfile) { - return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile); + @Validate.Profile String theProfile, RequestDetails theRequestDetails) { + return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile, theRequestDetails); } @Validate public MethodOutcome validate(@ResourceParam T theResource, @IdParam IdDt theId, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode, - @Validate.Profile String theProfile) { - return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile); + @Validate.Profile String theProfile, RequestDetails theRequestDetails) { + return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile, theRequestDetails); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java index 9a50b161efc..9c68e429a40 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java @@ -187,9 +187,9 @@ public class JpaSystemProviderDstu2 extends BaseJpaSystemProvider theNarrative, @Sort - SortSpec theSortSpec + SortSpec theSortSpec, + + RequestDetails theRequestDetails ) { //@formatter:on startRequest(theServletRequest); try { - return ((IFhirResourceDaoPatient) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative)); + return ((IFhirResourceDaoPatient) getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails); } finally { endRequest(theServletRequest); } @@ -87,6 +91,7 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu /** * /Patient/$everything + * @param theRequestDetails */ //@formatter:off @Operation(name = "everything", idempotent = true) @@ -111,13 +116,15 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu List theNarrative, @Sort - SortSpec theSortSpec + SortSpec theSortSpec, + + RequestDetails theRequestDetails ) { //@formatter:on startRequest(theServletRequest); try { - return ((IFhirResourceDaoPatient) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative)); + return ((IFhirResourceDaoPatient) getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec, toStringAndList(theContent), toStringAndList(theNarrative), theRequestDetails); } finally { endRequest(theServletRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderValueSetDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderValueSetDstu3.java index a46a8870caf..06bffaf0b0a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderValueSetDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderValueSetDstu3.java @@ -40,6 +40,7 @@ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; @@ -114,14 +115,15 @@ public class BaseJpaResourceProviderValueSetDstu3 extends JpaResourceProviderDst HttpServletRequest theServletRequest, @OperationParam(name="code", min=0, max=1) CodeType theCode, @OperationParam(name="system", min=0, max=1) UriType theSystem, - @OperationParam(name="coding", min=0, max=1) Coding theCoding + @OperationParam(name="coding", min=0, max=1) Coding theCoding, + RequestDetails theRequestDetails ) { //@formatter:on startRequest(theServletRequest); try { IFhirResourceDaoValueSet dao = (IFhirResourceDaoValueSet) getDao(); - LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding); + LookupCodeResult result = dao.lookupCode(theCode, theSystem, theCoding, theRequestDetails); if (result.isFound()==false) { throw new ResourceNotFoundException("Unable to find code[" + result.getSearchedForCode() + "] in system[" + result.getSearchedForSystem() + "]"); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java index 80ecda2e358..ce619203113 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java @@ -40,6 +40,7 @@ import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -58,13 +59,13 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes } @Create - public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional) { + public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam T theResource, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) { startRequest(theRequest); try { if (theConditional != null) { - return getDao().create(theResource, theConditional); + return getDao().create(theResource, theConditional, theRequestDetails); } else { - return getDao().create(theResource); + return getDao().create(theResource, theRequestDetails); } } finally { endRequest(theRequest); @@ -72,13 +73,13 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes } @Delete() - public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdType theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) { + public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdType theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional, RequestDetails theRequestDetails) { startRequest(theRequest); try { if (theConditional != null) { - return getDao().deleteByUrl(theConditional); + return getDao().deleteByUrl(theConditional, theRequestDetails); } else { - return getDao().delete(theResource); + return getDao().delete(theResource, theRequestDetails); } } finally { endRequest(theRequest); @@ -90,9 +91,9 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes @OperationParam(name="return", type=Meta.class) }) //@formatter:on - public Parameters meta() { + public Parameters meta(RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); - Meta metaGetOperation = getDao().metaGetOperation(Meta.class); + Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theRequestDetails); parameters.addParameter().setName("return").setValue(metaGetOperation); return parameters; } @@ -102,9 +103,9 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes @OperationParam(name="return", type=Meta.class) }) //@formatter:on - public Parameters meta(@IdParam IdType theId) { + public Parameters meta(@IdParam IdType theId, RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); - Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId); + Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId, theRequestDetails); parameters.addParameter().setName("return").setValue(metaGetOperation); return parameters; } @@ -114,12 +115,12 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes @OperationParam(name="return", type=Meta.class) }) //@formatter:on - public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta) { + public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) { if (theMeta == null) { throw new InvalidRequestException("Input contains no parameter with name 'meta'"); } Parameters parameters = new Parameters(); - Meta metaAddOperation = getDao().metaAddOperation(theId, theMeta); + Meta metaAddOperation = getDao().metaAddOperation(theId, theMeta, theRequestDetails); parameters.addParameter().setName("return").setValue(metaAddOperation); return parameters; } @@ -129,24 +130,24 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes @OperationParam(name="return", type=Meta.class) }) //@formatter:on - public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta) { + public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) { if (theMeta == null) { throw new InvalidRequestException("Input contains no parameter with name 'meta'"); } Parameters parameters = new Parameters(); - parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta)); + parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta, theRequestDetails)); return parameters; } @Update - public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdType theId, @ConditionalUrlParam String theConditional) { + public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam T theResource, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) { startRequest(theRequest); try { if (theConditional != null) { - return getDao().update(theResource, theConditional); + return getDao().update(theResource, theConditional, theRequestDetails); } else { theResource.setId(theId); - return getDao().update(theResource); + return getDao().update(theResource, theRequestDetails); } } finally { endRequest(theRequest); @@ -155,14 +156,14 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes @Validate public MethodOutcome validate(@ResourceParam T theResource, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode, - @Validate.Profile String theProfile) { - return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile); + @Validate.Profile String theProfile, RequestDetails theRequestDetails) { + return validate(theResource, null, theRawResource, theEncoding, theMode, theProfile, theRequestDetails); } @Validate public MethodOutcome validate(@ResourceParam T theResource, @IdParam IdType theId, @ResourceParam String theRawResource, @ResourceParam EncodingEnum theEncoding, @Validate.Mode ValidationModeEnum theMode, - @Validate.Profile String theProfile) { - return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile); + @Validate.Profile String theProfile, RequestDetails theRequestDetails) { + return getDao().validate(theResource, theId, theRawResource, theEncoding, theMode, theProfile, theRequestDetails); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java index 57bca21de14..f47ca76b68d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java @@ -189,9 +189,9 @@ public class JpaSystemProviderDstu3 extends BaseJpaSystemProvider @OperationParam(name="return", type=Meta.class) }) //@formatter:on - public Parameters meta() { + public Parameters meta(RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); - parameters.addParameter().setName("return").setValue(getDao().metaGetOperation()); + parameters.addParameter().setName("return").setValue(getDao().metaGetOperation(theRequestDetails)); return parameters; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu2.java index d7c5b5324e9..adadb621aa2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu2.java @@ -49,6 +49,7 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler implements ISubscriptionWebsocketHandler, Runnable { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionWebsocketHandlerDstu2.class); @@ -145,7 +146,7 @@ public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler impl public void closing() { ourLog.info("Deleting subscription {}", mySubscriptionId); try { - mySubscriptionDao.delete(mySubscriptionId); + mySubscriptionDao.delete(mySubscriptionId, new ServletRequestDetails()); } catch (Exception e) { handleFailure(e); } @@ -232,7 +233,7 @@ public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler impl } try { - Subscription subscription = mySubscriptionDao.read(id); + Subscription subscription = mySubscriptionDao.read(id, new ServletRequestDetails()); mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id); mySubscriptionId = subscription.getIdElement(); myState = new BoundStaticSubscipriptionState(theSession); @@ -269,7 +270,7 @@ public class SubscriptionWebsocketHandlerDstu2 extends TextWebSocketHandler impl } } - IIdType id = mySubscriptionDao.create(subscription).getId(); + IIdType id = mySubscriptionDao.create(subscription, new ServletRequestDetails()).getId(); mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id); mySubscriptionId = subscription.getIdElement(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu3.java index cafd1797755..d5c8c54bb71 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionWebsocketHandlerDstu3.java @@ -49,6 +49,7 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler implements ISubscriptionWebsocketHandler, Runnable { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionWebsocketHandlerDstu3.class); @@ -145,7 +146,7 @@ public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler impl public void closing() { ourLog.info("Deleting subscription {}", mySubscriptionId); try { - mySubscriptionDao.delete(mySubscriptionId); + mySubscriptionDao.delete(mySubscriptionId, new ServletRequestDetails()); } catch (Exception e) { handleFailure(e); } @@ -232,7 +233,7 @@ public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler impl } try { - Subscription subscription = mySubscriptionDao.read(id); + Subscription subscription = mySubscriptionDao.read(id, new ServletRequestDetails()); mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id); mySubscriptionId = subscription.getIdElement(); myState = new BoundStaticSubscipriptionState(theSession); @@ -269,7 +270,7 @@ public class SubscriptionWebsocketHandlerDstu3 extends TextWebSocketHandler impl } } - IIdType id = mySubscriptionDao.create(subscription).getId(); + IIdType id = mySubscriptionDao.create(subscription, new ServletRequestDetails()).getId(); mySubscriptionPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id); mySubscriptionId = subscription.getIdElement(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java index ab8d1c339ce..a1e4ef0d4d1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java @@ -37,6 +37,7 @@ import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.CoverageIgnore; /** @@ -100,7 +101,7 @@ public class SubscriptionsRequireManualActivationInterceptorDstu2 extends Interc if (requestId != null && requestId.hasIdPart()) { Subscription existing; try { - existing = myDao.read(requestId); + existing = myDao.read(requestId, new ServletRequestDetails()); SubscriptionStatusEnum existingStatus = existing.getStatusElement().getValueAsEnum(); if (existingStatus != newStatus) { verifyActiveStatus(subscription, newStatus, existingStatus); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java index fdd33d883fc..f485f2af619 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java @@ -38,6 +38,7 @@ import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.CoverageIgnore; /** @@ -101,7 +102,7 @@ public class SubscriptionsRequireManualActivationInterceptorDstu3 extends Interc if (requestId != null && requestId.hasIdPart()) { Subscription existing; try { - existing = myDao.read(requestId); + existing = myDao.read(requestId, new ServletRequestDetails()); SubscriptionStatus existingStatus = existing.getStatusElement().getValue(); if (existingStatus != newStatus) { verifyActiveStatus(subscription, newStatus, existingStatus); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java index ba5e1644f77..4c736fafd5d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java @@ -1,24 +1,19 @@ package ca.uhn.fhir.jpa.dao; -import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.util.List; - import org.hamcrest.core.StringContains; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.config.TestDstu1Config; -import ca.uhn.fhir.jpa.config.TestDstu2Config; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu.resource.Device; import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; @@ -28,11 +23,10 @@ import ca.uhn.fhir.model.dstu.resource.Observation; import ca.uhn.fhir.model.dstu.resource.Organization; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.StringDt; -import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @SuppressWarnings("unused") public class FhirResourceDaoDstu1Test extends BaseJpaTest { @@ -55,7 +49,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = ourPatientDao.create(p).getId(); + IIdType id = ourPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -63,7 +57,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { p.addName().addFamily("Hello"); p.setId("Patient/" + methodName); try { - ourPatientDao.create(p); + ourPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Can not create entity with ID[" + methodName + "], a resource with this ID already exists")); @@ -77,7 +71,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { p.addName().addFamily("Hello"); p.setId("Patient/123"); try { - ourPatientDao.create(p); + ourPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric")); @@ -90,7 +84,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01"); patient.setManagingOrganization(new ResourceReferenceDt("Patient/99999999")); try { - ourPatientDao.create(patient); + ourPatientDao.create(patient, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), StringContains.containsString("99999 not found")); @@ -104,17 +98,17 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsIdWhichPointsToForcedId01"); p1.addName().addFamily("Tester").addGiven("testUpdateRejectsIdWhichPointsToForcedId01"); p1.setId("ABABA"); - IIdType p1id = ourPatientDao.create(p1).getId(); + IIdType p1id = ourPatientDao.create(p1, new ServletRequestDetails()).getId(); assertEquals("ABABA", p1id.getIdPart()); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsIdWhichPointsToForcedId02"); p2.addName().addFamily("Tester").addGiven("testUpdateRejectsIdWhichPointsToForcedId02"); - IIdType p2id = ourPatientDao.create(p2).getId(); + IIdType p2id = ourPatientDao.create(p2, new ServletRequestDetails()).getId(); long p1longId = p2id.getIdPartAsLong() - 1; try { - ourPatientDao.read(new IdDt("Patient/" + p1longId)); + ourPatientDao.read(new IdDt("Patient/" + p1longId), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // good @@ -122,7 +116,7 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { try { p1.setId(new IdDt("Patient/" + p1longId)); - ourPatientDao.update(p1); + ourPatientDao.update(p1, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java index e37618e8cf7..daabb0ed5d2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java @@ -47,6 +47,7 @@ import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirSystemDaoDstu1Test extends BaseJpaTest { @@ -63,14 +64,14 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { public void testGetResourceCounts() { Observation obs = new Observation(); obs.getName().addCoding().setSystem("urn:system").setCode("testGetResourceCountsO01"); - ourObservationDao.create(obs); + ourObservationDao.create(obs, new ServletRequestDetails()); Map oldCounts = ourSystemDao.getResourceCounts(); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testGetResourceCountsP01"); patient.addName().addFamily("Tester").addGiven("Joe"); - ourPatientDao.create(patient); + ourPatientDao.create(patient, new ServletRequestDetails()); Map newCounts = ourSystemDao.getResourceCounts(); @@ -92,21 +93,21 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testHistory"); patient.addName().addFamily("Tester").addGiven("Joe"); - IIdType pid = ourPatientDao.create(patient).getId().toVersionless(); + IIdType pid = ourPatientDao.create(patient, new ServletRequestDetails()).getId().toVersionless(); Thread.sleep(10); patient.setId(pid); - IIdType newpid = ourPatientDao.update(patient).getId(); + IIdType newpid = ourPatientDao.update(patient, new ServletRequestDetails()).getId(); Thread.sleep(10); patient.setId(pid); - IIdType newpid2 = ourPatientDao.update(patient).getId(); + IIdType newpid2 = ourPatientDao.update(patient, new ServletRequestDetails()).getId(); Thread.sleep(10); patient.setId(pid); - IIdType newpid3 = ourPatientDao.update(patient).getId(); + IIdType newpid3 = ourPatientDao.update(patient, new ServletRequestDetails()).getId(); - IBundleProvider values = ourSystemDao.history(start); + IBundleProvider values = ourSystemDao.history(start, new ServletRequestDetails()); assertEquals(4, values.size()); List res = values.getResources(0, 4); @@ -117,18 +118,18 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { Location loc = new Location(); loc.getAddress().addLine("AAA"); - IIdType lid = ourLocationDao.create(loc).getId(); + IIdType lid = ourLocationDao.create(loc, new ServletRequestDetails()).getId(); Location loc2 = new Location(); loc2.getAddress().addLine("AAA"); - ourLocationDao.create(loc2).getId(); + ourLocationDao.create(loc2, new ServletRequestDetails()).getId(); Thread.sleep(2000); - values = ourLocationDao.history(start); + values = ourLocationDao.history(start, new ServletRequestDetails()); assertEquals(2, values.size()); - values = ourLocationDao.history(lid.getIdPartAsLong(), start); + values = ourLocationDao.history(lid.getIdPartAsLong(), start, new ServletRequestDetails()); assertEquals(1, values.size()); } @@ -219,44 +220,44 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { @Test public void testTagOperationss() throws Exception { - TagList preSystemTl = ourSystemDao.getAllTags(); + TagList preSystemTl = ourSystemDao.getAllTags(new ServletRequestDetails()); TagList tl1 = new TagList(); tl1.addTag("testGetAllTagsScheme1", "testGetAllTagsTerm1", "testGetAllTagsLabel1"); Patient p1 = new Patient(); p1.addIdentifier().setSystem("foo").setValue("testGetAllTags01"); ResourceMetadataKeyEnum.TAG_LIST.put(p1, tl1); - ourPatientDao.create(p1); + ourPatientDao.create(p1, new ServletRequestDetails()); TagList tl2 = new TagList(); tl2.addTag("testGetAllTagsScheme2", "testGetAllTagsTerm2", "testGetAllTagsLabel2"); Observation o1 = new Observation(); o1.getName().setText("testGetAllTags02"); ResourceMetadataKeyEnum.TAG_LIST.put(o1, tl2); - IIdType o1id = ourObservationDao.create(o1).getId(); + IIdType o1id = ourObservationDao.create(o1, new ServletRequestDetails()).getId(); assertTrue(o1id.getVersionIdPart() != null); - TagList postSystemTl = ourSystemDao.getAllTags(); + TagList postSystemTl = ourSystemDao.getAllTags(new ServletRequestDetails()); assertEquals(preSystemTl.size() + 2, postSystemTl.size()); assertEquals("testGetAllTagsLabel1", postSystemTl.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel()); - TagList tags = ourPatientDao.getAllResourceTags(); + TagList tags = ourPatientDao.getAllResourceTags(new ServletRequestDetails()); assertEquals("testGetAllTagsLabel1", tags.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1").getLabel()); assertNull(tags.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2")); - TagList tags2 = ourObservationDao.getTags(o1id); + TagList tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel()); o1.setId(o1id); - IIdType o1id2 = ourObservationDao.update(o1).getId(); + IIdType o1id2 = ourObservationDao.update(o1, new ServletRequestDetails()).getId(); assertTrue(o1id2.getVersionIdPart() != null); - tags2 = ourObservationDao.getTags(o1id); + tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertEquals("testGetAllTagsLabel2", tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2").getLabel()); - tags2 = ourObservationDao.getTags(o1id2); + tags2 = ourObservationDao.getTags(o1id2, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2")); @@ -264,12 +265,12 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { * Remove a tag from a version */ - ourObservationDao.removeTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme2", "testGetAllTagsTerm2"); - tags2 = ourObservationDao.getTags(o1id2); + ourObservationDao.removeTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme2", "testGetAllTagsTerm2", new ServletRequestDetails()); + tags2 = ourObservationDao.getTags(o1id2, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2")); - tags2 = ourObservationDao.getTags(o1id); + tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2")); @@ -277,13 +278,13 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { * Add a tag */ ourObservationDao.addTag(o1id2, TagTypeEnum.TAG, "testGetAllTagsScheme3", "testGetAllTagsTerm3", "testGetAllTagsLabel3"); - tags2 = ourObservationDao.getTags(o1id2); + tags2 = ourObservationDao.getTags(o1id2, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2")); assertNotNull(tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3")); assertEquals("testGetAllTagsLabel3", tags2.getTag("testGetAllTagsScheme3", "testGetAllTagsTerm3").getLabel()); - tags2 = ourObservationDao.getTags(o1id); + tags2 = ourObservationDao.getTags(o1id, new ServletRequestDetails()); assertNull(tags2.getTag("testGetAllTagsScheme1", "testGetAllTagsTerm1")); assertNotNull(tags2.getTag("testGetAllTagsScheme2", "testGetAllTagsTerm2")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java index 9120aa9b650..5d391157ede 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java @@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { @@ -48,7 +49,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { public void testJpaCreate() { Patient p = new Patient(); p.addName().addFamily("PATIENT"); - Long id = myPatientDao.create(p).getId().getIdPartAsLong(); + Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong(); ArgumentCaptor detailsCapt; ArgumentCaptor tableCapt; @@ -68,7 +69,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { */ p = new Patient(); p.addName().addFamily("PATIENT1"); - Long id2 = myPatientDao.create(p, "Patient?family=PATIENT").getId().getIdPartAsLong(); + Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", new ServletRequestDetails()).getId().getIdPartAsLong(); assertEquals(id, id2); detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); @@ -82,9 +83,9 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { public void testJpaDelete() { Patient p = new Patient(); p.addName().addFamily("PATIENT"); - Long id = myPatientDao.create(p).getId().getIdPartAsLong(); + Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong(); - myPatientDao.delete(new IdDt("Patient", id)); + myPatientDao.delete(new IdDt("Patient", id), new ServletRequestDetails()); ArgumentCaptor detailsCapt; ArgumentCaptor tableCapt; @@ -102,12 +103,12 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { public void testJpaUpdate() { Patient p = new Patient(); p.addName().addFamily("PATIENT"); - Long id = myPatientDao.create(p).getId().getIdPartAsLong(); + Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong(); p = new Patient(); p.setId(new IdDt(id)); p.addName().addFamily("PATIENT1"); - Long id2 = myPatientDao.update(p).getId().getIdPartAsLong(); + Long id2 = myPatientDao.update(p, new ServletRequestDetails()).getId().getIdPartAsLong(); assertEquals(id, id2); ArgumentCaptor detailsCapt; @@ -126,7 +127,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { p = new Patient(); p.setId(new IdDt(id)); p.addName().addFamily("PATIENT2"); - id2 = myPatientDao.update(p, "Patient?family=PATIENT1").getId().getIdPartAsLong(); + id2 = myPatientDao.update(p, "Patient?family=PATIENT1", new ServletRequestDetails()).getId().getIdPartAsLong(); assertEquals(id, id2); detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); @@ -141,7 +142,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { p = new Patient(); p.addName().addFamily("PATIENT3"); - id2 = myPatientDao.update(p, "Patient?family=ZZZ").getId().getIdPartAsLong(); + id2 = myPatientDao.update(p, "Patient?family=ZZZ", new ServletRequestDetails()).getId().getIdPartAsLong(); assertNotEquals(id, id2); detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java index 3217a6c9ce8..36e012ee2c2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java @@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { @@ -37,7 +38,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { public void testSuggestIgnoresBase64Content() { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Media med = new Media(); med.getSubject().setReference(ptId); @@ -45,7 +46,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { med.getContent().setContentType("LCws"); med.getContent().setData(new Base64BinaryDt(new byte[] {44,44,44,44,44,44,44,44})); med.getContent().setTitle("bbbb syst"); - myMediaDao.create(med); + myMediaDao.create(med, new ServletRequestDetails()); ourLog.info(myFhirCtx.newJsonParser().encodeResourceToString(med)); List output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "press"); @@ -77,35 +78,35 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { public void testSuggest() { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReference(ptId); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); obs = new Observation(); obs.getSubject().setReference(ptId); obs.getCode().setText("MNBVCXZ"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); obs = new Observation(); obs.getSubject().setReference(ptId); obs.getCode().setText("ZXC HELLO"); obs.addComponent().getCode().setText("HHHHHHHHHH"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); /* * These shouldn't match since they're for another patient */ patient = new Patient(); patient.addName().addFamily("testSuggest2"); - IIdType ptId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReference(ptId2); obs2.getCode().setText("ZXCVBNMZZ"); - myObservationDao.create(obs2); + myObservationDao.create(obs2, new ServletRequestDetails()); List output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "ZXCVBNM"); ourLog.info("Found: " + output); @@ -150,7 +151,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { patient = new Patient(); patient.getText().setDiv("
DIVAAA
"); patient.addName().addGiven("NAMEAAA"); - IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -168,7 +169,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { patient.setId(pId1); patient.getText().setDiv("
DIVBBB
"); patient.addName().addGiven("NAMEBBB"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -192,19 +193,19 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { public void testEverythingInstanceWithContentFilter() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); - IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); + IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); - myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); + myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.getText().setDiv("
OBSTEXT1
"); @@ -212,19 +213,19 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs1.getCode().addCoding().setCode("CODE1"); obs1.setValue(new StringDt("obsvalue1")); obs1.getDevice().setReference(devId1); - IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReference(ptId1); obs2.getCode().addCoding().setCode("CODE2"); obs2.setValue(new StringDt("obsvalue2")); - IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs3 = new Observation(); obs3.getSubject().setReference(ptId2); obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringDt("obsvalue3")); - IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); + IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); HttpServletRequest request; List actual; @@ -235,16 +236,16 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1)); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obstext1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1)); request = mock(HttpServletRequest.class); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId2, devId1)); /* @@ -255,12 +256,12 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs4.getSubject().setReference(ptId1); obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringDt("obsvalue1")); - IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless(); + IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId4, devId1)); /* @@ -272,11 +273,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs1.getSubject().setReference(ptId1); obs1.getCode().addCoding().setCode("CODE2"); obs1.setValue(new StringDt("obsvalue2")); - myObservationDao.update(obs1); + myObservationDao.update(obs1, new ServletRequestDetails()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId4)); } @@ -285,38 +286,38 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { public void testEverythingTypeWithContentFilter() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); - IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); + IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); - IIdType devId2 = myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); + IIdType devId2 = myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.getSubject().setReference(ptId1); obs1.getCode().addCoding().setCode("CODE1"); obs1.setValue(new StringDt("obsvalue1")); obs1.getDevice().setReference(devId1); - IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReference(ptId1); obs2.getCode().addCoding().setCode("CODE2"); obs2.setValue(new StringDt("obsvalue2")); - IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs3 = new Observation(); obs3.getSubject().setReference(ptId2); obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringDt("obsvalue3")); - IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); + IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); HttpServletRequest request; List actual; @@ -327,11 +328,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1)); request = mock(HttpServletRequest.class); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, null, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId2, devId1, ptId2, obsId3)); /* @@ -342,12 +343,12 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs4.getSubject().setReference(ptId1); obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringDt("obsvalue1")); - IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless(); + IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId1, obsId4, devId1)); /* @@ -359,11 +360,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs1.getSubject().setReference(ptId1); obs1.getCode().addCoding().setCode("CODE2"); obs1.setValue(new StringDt("obsvalue2")); - myObservationDao.update(obs1); + myObservationDao.update(obs1, new ServletRequestDetails()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIds(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(ptId1, obsId4)); } @@ -381,7 +382,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { patient = new Patient(); patient.getText().setDiv("
DIVAAA
"); patient.addName().addGiven("NAMEAAA"); - IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -399,7 +400,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { patient.setId(pId1); patient.getText().setDiv("
DIVBBB
"); patient.addName().addGiven("NAMEBBB"); - myPatientDao.update(patient, null, false); + myPatientDao.update(patient, null, false, new ServletRequestDetails()); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -408,7 +409,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), not(contains(pId1))); - myPatientDao.update(patient, null, true); + myPatientDao.update(patient, null, true, new ServletRequestDetails()); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -436,18 +437,18 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addName().addGiven(methodName); patient.addAddress().addLine("My fulltext address"); - pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Observation obs = new Observation(); obs.getSubject().setReference(pId1); obs.setValue(new StringDt("This is the FULLtext of the observation")); - IIdType oId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType oId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId1); obs.setValue(new StringDt("Another fullText")); - IIdType oId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType oId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List patients; SearchParameterMap params; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index 7f33bc9d889..8af3159e324 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -96,6 +96,7 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @@ -107,7 +108,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { subs.setStatus(SubscriptionStatusEnum.ACTIVE); subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setCriteria("Observation?"); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map = new SearchParameterMap(); map.add(Subscription.SP_TYPE, new TokenParam(null, SubscriptionChannelTypeEnum.WEBSOCKET.getCode())); @@ -121,33 +122,33 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Medication med = new Medication(); med.getCode().setText(methodName); - IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); + IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat = new Patient(); pat.addAddress().addLine(methodName); pat.getManagingOrganization().setReference(orgId); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat2 = new Patient(); pat2.addAddress().addLine(methodName); pat2.getManagingOrganization().setReference(orgId); - IIdType patId2 = myPatientDao.create(pat2).getId().toUnqualifiedVersionless(); + IIdType patId2 = myPatientDao.create(pat2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); MedicationOrder mo = new MedicationOrder(); mo.getPatient().setReference(patId); mo.setMedication(new ResourceReferenceDt(medId)); - IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); + IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); HttpServletRequest request = mock(HttpServletRequest.class); - IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null); + IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails()); assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId, patId2)); request = mock(HttpServletRequest.class); - resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null); + resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null, new ServletRequestDetails()); assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId)); } @@ -161,7 +162,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z")); order.addItem().addEvent().setDateTime(new DateTimeDt("2011-12-12T11:12:12Z")); - IIdType id = myDiagnosticOrderDao.create(order).getId().toUnqualifiedVersionless(); + IIdType id = myDiagnosticOrderDao.create(order, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual = toUnqualifiedVersionlessIds(myDiagnosticOrderDao.search(DiagnosticOrder.SP_ITEM_DATE, new DateParam("2011-12-12T11:12:12Z"))); assertThat(actual, contains(id)); @@ -182,7 +183,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { res.addVaccinationProtocol().setDoseSequence(2); res.addVaccinationProtocol().setDoseSequence(2); - IIdType id = myImmunizationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myImmunizationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual = toUnqualifiedVersionlessIds(myImmunizationDao.search(Immunization.SP_DOSE_SEQUENCE, new NumberParam("1"))); assertThat(actual, contains(id)); @@ -201,7 +202,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232); res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232); - IIdType id = mySubstanceDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = mySubstanceDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamQuantity.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -217,11 +218,11 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Practitioner pract = new Practitioner(); pract.setId("Practitioner/somepract"); pract.getName().addFamily("SOME PRACT"); - myPractitionerDao.update(pract); + myPractitionerDao.update(pract, new ServletRequestDetails()); Practitioner pract2 = new Practitioner(); pract2.setId("Practitioner/somepract2"); pract2.getName().addFamily("SOME PRACT2"); - myPractitionerDao.update(pract2); + myPractitionerDao.update(pract2, new ServletRequestDetails()); DiagnosticOrder res = new DiagnosticOrder(); res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract")); @@ -229,7 +230,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract2")); res.addEvent().setActor(new ResourceReferenceDt("Practitioner/somepract2")); - IIdType id = myDiagnosticOrderDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myDiagnosticOrderDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceLink.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -250,7 +251,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { p.addAddress().addLine("456 Fake Street"); p.addAddress().addLine("456 Fake Street"); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamString.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -269,7 +270,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { res.addIdentifier().setSystem("http://foo2").setValue("1234"); res.addIdentifier().setSystem("http://foo2").setValue("1234"); - IIdType id = myPatientDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamToken.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -288,7 +289,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { res.addElement().addTarget().addDependsOn().setElement("http://bar"); res.addElement().addTarget().addDependsOn().setElement("http://bar"); - IIdType id = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamUri.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -305,13 +306,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester").addGiven("Joe"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -325,13 +326,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } IIdType id2; { Organization patient = new Organization(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myOrganizationDao.create(patient).getId(); + id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId(); } Map params = new HashMap(); @@ -352,13 +353,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } SearchParameterMap params; @@ -400,14 +401,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } long betweenTime = System.currentTimeMillis(); IIdType id2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } SearchParameterMap params = new SearchParameterMap(); @@ -437,13 +438,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Organization patient = new Organization(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myOrganizationDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } SearchParameterMap params = new SearchParameterMap(); @@ -457,12 +458,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01"); o1.setValue(new StringDt("testSearchCompositeParamS01")); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01"); o2.setValue(new StringDt("testSearchCompositeParamS02")); - IIdType id2 = myObservationDao.create(o2).getId(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId(); { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01"); @@ -487,12 +488,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01"); o1.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01T11:11:11"))); - IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01"); o2.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01T12:12:12"))); - IIdType id2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); @@ -526,7 +527,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.setLanguage(new CodeDt("TEST")); patient.addName().addFamily("TEST"); patient.addIdentifier().setSystem("TEST").setValue("TEST"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -542,7 +543,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { params.put(Patient.SP_NAME, new StringParam("TEST")); assertEquals(1, toList(myPatientDao.search(params)).size()); - myPatientDao.delete(new IdDt("Patient/TEST")); + myPatientDao.delete(new IdDt("Patient/TEST"), new ServletRequestDetails()); params = new HashMap(); params.put("_id", new StringDt("TEST")); @@ -577,7 +578,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.getLanguage().setValue("en_CA"); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } IIdType id2; { @@ -585,7 +586,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.getLanguage().setValue("en_US"); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("testSearchLanguageParam").addGiven("John"); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Map params = new HashMap(); @@ -617,7 +618,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.getLanguage().setValue("en_CA"); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Date betweenTime = new Date(); @@ -628,7 +629,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.getLanguage().setValue("en_US"); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("testSearchLanguageParam").addGiven("John"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { SearchParameterMap params = new SearchParameterMap(); @@ -712,14 +713,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily(methodName).addGiven("Joe"); - id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id1b; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily(methodName + "XXXX").addGiven("Joe"); - id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Thread.sleep(1100); @@ -731,7 +732,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily(methodName).addGiven("John"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -776,7 +777,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id0 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id0 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } int sleep = 100; @@ -789,18 +790,18 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id1b; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } - ourLog.info("Res 1: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id0)).getValueAsString()); - ourLog.info("Res 2: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1a)).getValueAsString()); - InstantDt id1bpublished = ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1b)); + ourLog.info("Res 1: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id0, new ServletRequestDetails())).getValueAsString()); + ourLog.info("Res 2: {}", ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1a, new ServletRequestDetails())).getValueAsString()); + InstantDt id1bpublished = ResourceMetadataKeyEnum.PUBLISHED.get(myPatientDao.read(id1b, new ServletRequestDetails())); ourLog.info("Res 3: {}", id1bpublished.getValueAsString()); Thread.sleep(sleep); @@ -841,13 +842,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("testSearchNameParam01Fam").addGiven("testSearchNameParam01Giv"); ResourceMetadataKeyEnum.TITLE.put(patient, "P1TITLE"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("testSearchNameParam02Fam").addGiven("testSearchNameParam02Giv"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -891,7 +892,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Location loc = new Location(); loc.getPosition().setLatitude(43.7); loc.getPosition().setLatitude(79.4); - myLocationDao.create(loc); + myLocationDao.create(loc, new ServletRequestDetails()); } } @@ -900,12 +901,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Encounter e1 = new Encounter(); e1.addIdentifier().setSystem("foo").setValue("testSearchNumberParam01"); e1.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60); - IIdType id1 = myEncounterDao.create(e1).getId(); + IIdType id1 = myEncounterDao.create(e1, new ServletRequestDetails()).getId(); Encounter e2 = new Encounter(); e2.addIdentifier().setSystem("foo").setValue("testSearchNumberParam02"); e2.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(2.0); - IIdType id2 = myEncounterDao.create(e2).getId(); + IIdType id2 = myEncounterDao.create(e2, new ServletRequestDetails()).getId(); { IBundleProvider found = myEncounterDao.search(Encounter.SP_LENGTH, new NumberParam(">2")); assertEquals(2, found.size()); @@ -933,7 +934,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.addName().addFamily(name); - id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Map params = new HashMap(); @@ -944,7 +945,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem(name).setValue(name); patient.setId(id); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); params = new HashMap(); params.put(Patient.SP_FAMILY, new StringDt(name)); @@ -961,14 +962,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Practitioner patient = new Practitioner(); patient.getName().addFamily(methodName); patient.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setValue("123"); - id1 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Practitioner patient = new Practitioner(); patient.getName().addFamily(methodName); patient.addTelecom().setSystem(ContactPointSystemEnum.EMAIL).setValue("abc"); - id2 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Map params; @@ -1007,27 +1008,27 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX"); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain01"); - IIdType patientId01 = myPatientDao.create(patient).getId(); + IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Patient patient02 = new Patient(); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX"); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain02"); - IIdType patientId02 = myPatientDao.create(patient02).getId(); + IIdType patientId02 = myPatientDao.create(patient02, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeDt(new Date())); obs01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeDt(new Date())); obs02.setSubject(new ResourceReferenceDt(patientId02)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); // Create another type, that shouldn't be returned DiagnosticReport dr01 = new DiagnosticReport(); dr01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType drId01 = myDiagnosticReportDao.create(dr01).getId(); + IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 }); @@ -1061,19 +1062,19 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId01 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId01 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Location locParent = new Location(); locParent.setManagingOrganization(new ResourceReferenceDt(orgId01)); - IIdType locParentId = myLocationDao.create(locParent).getId().toUnqualifiedVersionless(); + IIdType locParentId = myLocationDao.create(locParent, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Location locChild = new Location(); locChild.setPartOf(new ResourceReferenceDt(locParentId)); - IIdType locChildId = myLocationDao.create(locChild).getId().toUnqualifiedVersionless(); + IIdType locChildId = myLocationDao.create(locChild, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Location locGrandchild = new Location(); locGrandchild.setPartOf(new ResourceReferenceDt(locChildId)); - IIdType locGrandchildId = myLocationDao.create(locGrandchild).getId().toUnqualifiedVersionless(); + IIdType locGrandchildId = myLocationDao.create(locGrandchild, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider found; ReferenceParam param; @@ -1106,21 +1107,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01"); patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypesXX"); - IIdType patientId01 = myPatientDao.create(patient).getId(); + IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Location loc01 = new Location(); loc01.getNameElement().setValue("testSearchResourceLinkWithChainWithMultipleTypes01"); - IIdType locId01 = myLocationDao.create(loc01).getId(); + IIdType locId01 = myLocationDao.create(loc01, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeDt(new Date())); obs01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeDt(new Date())); obs02.setSubject(new ResourceReferenceDt(locId01)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 }); @@ -1147,28 +1148,28 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.setId("testSearchResourceLinkWithTextLogicalId01"); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX"); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId01"); - IIdType patientId01 = myPatientDao.update(patient).getId(); + IIdType patientId01 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); Patient patient02 = new Patient(); patient02.setId("testSearchResourceLinkWithTextLogicalId02"); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX"); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId02"); - IIdType patientId02 = myPatientDao.update(patient02).getId(); + IIdType patientId02 = myPatientDao.update(patient02, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeDt(new Date())); obs01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeDt(new Date())); obs02.setSubject(new ResourceReferenceDt(patientId02)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); // Create another type, that shouldn't be returned DiagnosticReport dr01 = new DiagnosticReport(); dr01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType drId01 = myDiagnosticReportDao.create(dr01).getId(); + IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 }); @@ -1199,13 +1200,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testSearchStringParam").addGiven("Joe"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -1230,12 +1231,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily(value); - longId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + longId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); - shortId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + shortId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Map params = new HashMap(); @@ -1254,13 +1255,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -1282,12 +1283,12 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001"); patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1"); patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem").setDisplay("testSearchTokenParamDisplay"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam002"); patient.addName().addFamily("Tester").addGiven("testSearchTokenParam2"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); { SearchParameterMap map = new SearchParameterMap(); @@ -1390,7 +1391,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { QuantityDt q = new QuantityDt().setSystem("urn:bar:" + methodName).setCode(methodName + "units").setValue(100); o.setValue(q); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, null); found = myObservationDao.searchForIds("value-quantity", param); @@ -1429,7 +1430,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; IIdType patientId; @@ -1437,20 +1438,20 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new ResourceReferenceDt(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); patient.addCareProvider().setReference(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType practId2; { Practitioner pract = new Practitioner(); pract.getName().addFamily(methodName + "_PRACT1"); - practId2 = myPractitionerDao.create(pract).getId().toUnqualifiedVersionless(); + practId2 = myPractitionerDao.create(pract, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId2; { @@ -1458,7 +1459,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_" + methodName + "_P2").addGiven("John"); patient.addCareProvider().setReference(practId2); - patientId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1561,21 +1562,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new ResourceReferenceDt(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new ResourceReferenceDt(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1583,7 +1584,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1603,21 +1604,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new ResourceReferenceDt(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new ResourceReferenceDt(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1625,7 +1626,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1645,21 +1646,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new ResourceReferenceDt(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new ResourceReferenceDt(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1667,7 +1668,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1686,21 +1687,21 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new ResourceReferenceDt(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new ResourceReferenceDt(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1708,7 +1709,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1729,20 +1730,20 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Organization org = new Organization(); org.setId("testSearchWithIncludesThatHaveTextIdid1"); org.getNameElement().setValue("testSearchWithIncludesThatHaveTextId_O1"); - IIdType orgId = myOrganizationDao.update(org).getId(); + IIdType orgId = myOrganizationDao.update(org, new ServletRequestDetails()).getId(); assertThat(orgId.getValue(), endsWith("Organization/testSearchWithIncludesThatHaveTextIdid1/_history/1")); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P2").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } SearchParameterMap params = new SearchParameterMap(); @@ -1763,13 +1764,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @Test public void testSearchWithMissingDate() { - IIdType orgId = myOrganizationDao.create(new Organization()).getId(); + IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId(); IIdType notMissing; IIdType missing; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); @@ -1777,7 +1778,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); patient.setBirthDate(new DateDt("2011-01-01")); patient.getManagingOrganization().setReference(orgId); - notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Date Param { @@ -1807,13 +1808,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("002"); obs.setValue(new QuantityDt(123)); - notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Quantity Param { @@ -1838,13 +1839,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @Test public void testSearchWithMissingReference() { - IIdType orgId = myOrganizationDao.create(new Organization()).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IIdType notMissing; IIdType missing; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); @@ -1852,7 +1853,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); patient.setBirthDate(new DateDt("2011-01-01")); patient.getManagingOrganization().setReference(orgId); - notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Reference Param { @@ -1878,13 +1879,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @Test public void testSearchWithMissingString() { - IIdType orgId = myOrganizationDao.create(new Organization()).getId(); + IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId(); IIdType notMissing; IIdType missing; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); @@ -1892,7 +1893,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); patient.setBirthDate(new DateDt("2011-01-01")); patient.getManagingOrganization().setReference(orgId); - notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // String Param { @@ -1919,13 +1920,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { public void testSearchWithNoResults() { Device dev = new Device(); dev.addIdentifier().setSystem("Foo"); - myDeviceDao.create(dev); + myDeviceDao.create(dev, new ServletRequestDetails()); IBundleProvider value = myDeviceDao.search(new SearchParameterMap()); ourLog.info("Initial size: " + value.size()); for (IBaseResource next : value.getResources(0, value.size())) { ourLog.info("Deleting: {}", next.getIdElement()); - myDeviceDao.delete((IIdType) next.getIdElement()); + myDeviceDao.delete((IIdType) next.getIdElement(), new ServletRequestDetails()); } value = myDeviceDao.search(new SearchParameterMap()); @@ -1951,7 +1952,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { List security = new ArrayList(); security.add(new CodingDt("urn:taglist", methodName + "1a")); ResourceMetadataKeyEnum.SECURITY_LABELS.put(org, security); - tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType tag2id; { @@ -1960,7 +1961,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { List security = new ArrayList(); security.add(new IdDt("http://" + methodName)); ResourceMetadataKeyEnum.PROFILES.put(org, security); - tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { SearchParameterMap params = new SearchParameterMap(); @@ -1988,7 +1989,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { tagList.addTag("urn:taglist", methodName + "1a"); tagList.addTag("urn:taglist", methodName + "1b"); ResourceMetadataKeyEnum.TAG_LIST.put(org, tagList); - tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Date betweenDate = new Date(); @@ -2001,7 +2002,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { tagList.addTag("urn:taglist", methodName + "2a"); tagList.addTag("urn:taglist", methodName + "2b"); ResourceMetadataKeyEnum.TAG_LIST.put(org, tagList); - tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -2071,13 +2072,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("002"); obs.getCode().addCoding().setSystem("urn:system").setCode("002"); - notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Token Param { @@ -2105,7 +2106,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { Class type = ValueSet.class; String resourceName = "/valueset-dstu2.json"; ValueSet vs = loadResourceFromClasspath(type, resourceName); - myValueSetDao.update(vs); + myValueSetDao.update(vs, new ServletRequestDetails()); IBundleProvider result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/fhir/ValueSet/basic-resource-type")); assertThat(toUnqualifiedVersionlessIds(result), contains((IIdType) new IdDt("ValueSet/testSearchWithUriParam"))); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java index 2d14f77703c..36774b2c053 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java @@ -38,6 +38,7 @@ import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { @@ -64,16 +65,16 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setStatus(SubscriptionStatusEnum.REQUESTED); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); mySubscriptionDao.purgeInactiveSubscriptions(); - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); Thread.sleep(1500); myDaoConfig.setSchedulingDisabled(false); mySubscriptionDao.purgeInactiveSubscriptions(); try { - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -95,9 +96,9 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setStatus(SubscriptionStatusEnum.REQUESTED); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); mySubscriptionDao.purgeInactiveSubscriptions(); - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); mySubscriptionDao.getUndeliveredResourcesAndPurge(mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id)); @@ -106,7 +107,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { myDaoConfig.setSchedulingDisabled(false); mySubscriptionDao.purgeInactiveSubscriptions(); try { - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -120,7 +121,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setStatus(SubscriptionStatusEnum.REQUESTED); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); TypedQuery q = myEntityManager.createQuery("SELECT t from SubscriptionTable t WHERE t.mySubscriptionResource.myId = :id", SubscriptionTable.class); q.setParameter("id", id.getIdPartAsLong()); @@ -130,15 +131,15 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { assertNotNull(table.getNextCheck()); assertEquals(table.getNextCheck(), table.getSubscriptionResource().getPublished().getValue()); assertEquals(SubscriptionStatusEnum.REQUESTED.getCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus()); - assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValueAsEnum()); + assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValueAsEnum()); subs.setStatus(SubscriptionStatusEnum.ACTIVE); - mySubscriptionDao.update(subs); + mySubscriptionDao.update(subs, new ServletRequestDetails()); assertEquals(SubscriptionStatusEnum.ACTIVE.getCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus()); - assertEquals(SubscriptionStatusEnum.ACTIVE, mySubscriptionDao.read(id).getStatusElement().getValueAsEnum()); + assertEquals(SubscriptionStatusEnum.ACTIVE, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValueAsEnum()); - mySubscriptionDao.delete(id); + mySubscriptionDao.delete(id, new ServletRequestDetails()); assertNull(myEntityManager.find(SubscriptionTable.class, table.getId())); @@ -151,10 +152,10 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setId(id); subs.setStatus(SubscriptionStatusEnum.REQUESTED); - mySubscriptionDao.update(subs); + mySubscriptionDao.update(subs, new ServletRequestDetails()); assertEquals(SubscriptionStatusEnum.REQUESTED.getCode(), myEntityManager.createQuery("SELECT t FROM SubscriptionTable t WHERE t.myResId = " + id.getIdPart(), SubscriptionTable.class).getSingleResult().getStatus()); - assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValueAsEnum()); + assertEquals(SubscriptionStatusEnum.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValueAsEnum()); } @Test @@ -163,7 +164,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.setStatus(SubscriptionStatusEnum.REQUESTED); subs.setCriteria("Observation"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\"")); @@ -173,7 +174,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.setStatus(SubscriptionStatusEnum.REQUESTED); subs.setCriteria("http://foo.com/Observation?AAA=BBB"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\"")); @@ -183,7 +184,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.setStatus(SubscriptionStatusEnum.REQUESTED); subs.setCriteria("ObservationZZZZ?a=b"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.criteria contains invalid/unsupported resource type: ObservationZZZZ")); @@ -193,7 +194,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.setStatus(SubscriptionStatusEnum.REQUESTED); subs.setCriteria("Observation?identifier=123"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.channel.type must be populated on this server")); @@ -203,7 +204,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.setStatus(SubscriptionStatusEnum.REQUESTED); subs.setCriteria("Observation?identifier=123"); subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); - assertTrue(mySubscriptionDao.create(subs).getId().hasIdPart()); + assertTrue(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().hasIdPart()); } @@ -214,7 +215,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { String methodName = "testDeleteSubscriptionWithFlaggedResources"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs; @@ -226,7 +227,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatusEnum.ACTIVE); - IIdType subsId = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Long subsPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(subsId); assertNull(mySubscriptionTableDao.findOne(subsPid).getLastClientPoll()); @@ -239,12 +240,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { Observation obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -258,7 +259,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { * Delete the subscription */ - mySubscriptionDao.delete(subsId); + mySubscriptionDao.delete(subsId, new ServletRequestDetails()); assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L))); assertThat(mySubscriptionTableDao.count(), not(greaterThan(0L))); @@ -266,14 +267,14 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { /* * Delete a second time just to make sure that works */ - mySubscriptionDao.delete(subsId); + mySubscriptionDao.delete(subsId, new ServletRequestDetails()); /* * Re-create the subscription */ subs.setId(subsId); - mySubscriptionDao.update(subs).getId(); + mySubscriptionDao.update(subs, new ServletRequestDetails()).getId(); assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L))); assertThat(mySubscriptionTableDao.count(), (greaterThan(0L))); @@ -285,7 +286,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -302,12 +303,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { String methodName = "testSubscriptionResourcesAppear"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs; @@ -319,13 +320,13 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatusEnum.ACTIVE); - Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId()); + Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId()); subs = new Subscription(); subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatusEnum.ACTIVE); - Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId()); + Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId()); assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll()); @@ -335,12 +336,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -381,7 +382,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { */ mySystemDao.markAllResourcesForReindexing(); - mySystemDao.performReindexingPass(100); + mySystemDao.performReindexingPass(100, new ServletRequestDetails()); assertEquals(0, mySubscriptionDao.pollForNewUndeliveredResources()); @@ -394,7 +395,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { ourLog.info("Updating observation"); Observation nextObs = (Observation) next; nextObs.addPerformer().setDisplay("Some display"); - myObservationDao.update(nextObs); + myObservationDao.update(nextObs, new ServletRequestDetails()); } assertEquals(6, mySubscriptionDao.pollForNewUndeliveredResources()); @@ -410,12 +411,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { String methodName = "testSubscriptionResourcesAppear2"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType oId = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType oId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs; @@ -427,7 +428,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatusEnum.ACTIVE); - Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId()); + Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId()); assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll()); @@ -435,7 +436,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { ourLog.info("pId: {} - oId: {}", pId, oId); - myObservationDao.update(myObservationDao.read(oId)); + myObservationDao.update(myObservationDao.read(oId, new ServletRequestDetails()), new ServletRequestDetails()); assertEquals(1, mySubscriptionDao.pollForNewUndeliveredResources()); ourLog.info("Between passes"); @@ -447,12 +448,12 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -476,7 +477,7 @@ public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); mySubscriptionDao.pollForNewUndeliveredResources(); assertEquals(4, mySubscriptionFlaggedResourceDataDao.count()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java index 32c16c7a39c..3e430822d0d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java @@ -105,6 +105,7 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { @@ -169,7 +170,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { tl.add(new Tag(methodName, methodName)); ResourceMetadataKeyEnum.TAG_LIST.put(org, tl); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map = new SearchParameterMap(); map.add("_language", new StringParam("EN_ca")); @@ -179,7 +180,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { map.add("_tag", new TokenParam(methodName, methodName)); assertEquals(1, myOrganizationDao.search(map).size()); - myOrganizationDao.delete(orgId); + myOrganizationDao.delete(orgId, new ServletRequestDetails()); map = new SearchParameterMap(); map.add("_language", new StringParam("EN_ca")); @@ -195,7 +196,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); o1.setValue(new CodeableConceptDt("testChoiceParam01CCS", "testChoiceParam01CCV")); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_CONCEPT, new TokenParam("testChoiceParam01CCS", "testChoiceParam01CCV")); @@ -209,7 +210,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testChoiceParam02"); o2.setValue(new PeriodDt().setStart(new DateTimeDt("2001-01-01")).setEnd(new DateTimeDt("2001-01-03"))); - IIdType id2 = myObservationDao.create(o2).getId(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_DATE, new DateParam("2001-01-02")); @@ -223,7 +224,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testChoiceParamDateAlt02"); o2.setEffective(new DateTimeDt("2015-03-08T11:11:11")); - IIdType id2 = myObservationDao.create(o2).getId(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId(); { Set found = myObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2001-01-02")); @@ -240,7 +241,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Observation o3 = new Observation(); o3.getCode().addCoding().setSystem("foo").setCode("testChoiceParam03"); o3.setValue(new QuantityDt(QuantityComparatorEnum.GREATER_THAN, 123.0, "foo", "bar").setCode("bar")); - IIdType id3 = myObservationDao.create(o3).getId(); + IIdType id3 = myObservationDao.create(o3, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_QUANTITY, new QuantityParam(">100", "foo", "bar")); @@ -300,7 +301,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Observation o4 = new Observation(); o4.getCode().addCoding().setSystem("foo").setCode("testChoiceParam04"); o4.setValue(new StringDt("testChoiceParam04Str")); - IIdType id4 = myObservationDao.create(o4).getId(); + IIdType id4 = myObservationDao.create(o4, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_STRING, new StringParam("testChoiceParam04Str")); @@ -354,7 +355,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { ResourceMetadataKeyEnum.TAG_LIST.put(p, tl); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("subsetted")); @@ -368,7 +369,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/ABC"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not create resource with ID[ABC], ID must not be supplied")); @@ -382,7 +383,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/abc"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not create resource with ID[abc], ID must not be supplied")); @@ -396,7 +397,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); // Verify interceptor @@ -412,7 +413,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Hello"); - results = myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName); + results = myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); assertEquals(id.getIdPart(), results.getId().getIdPart()); assertFalse(results.getCreated().booleanValue()); @@ -423,7 +424,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Hello"); - results = myPatientDao.create(p); + results = myPatientDao.create(p, new ServletRequestDetails()); assertNotEquals(id.getIdPart(), results.getId().getIdPart()); assertTrue(results.getCreated().booleanValue()); @@ -433,7 +434,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Hello"); try { - myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName); + myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); fail(); } catch (PreconditionFailedException e) { assertThat(e.getMessage(), containsString("Failed to CREATE")); @@ -445,12 +446,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testCreateWithIllegalReference() { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); - IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); try { Patient p = new Patient(); p.getManagingOrganization().setReference(id1); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Invalid reference found at path 'Patient.managingOrganization'. Resource type 'Observation' is not valid for this path", e.getMessage()); @@ -459,7 +460,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { try { Patient p = new Patient(); p.getManagingOrganization().setReference(new IdDt("Organization", id1.getIdPart())); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Resource contains reference to Organization/" + id1.getIdPart() + " but resource with ID " + id1.getIdPart() + " is actually of type Observation", e.getMessage()); @@ -470,12 +471,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { o1 = new Observation(); o1.setId("testCreateWithIllegalReference"); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); - id1 = myObservationDao.update(o1).getId().toUnqualifiedVersionless(); + id1 = myObservationDao.update(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); try { Patient p = new Patient(); p.getManagingOrganization().setReference(id1); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Invalid reference found at path 'Patient.managingOrganization'. Resource type 'Observation' is not valid for this path", e.getMessage()); @@ -484,7 +485,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { try { Patient p = new Patient(); p.getManagingOrganization().setReference(new IdDt("Organization", id1.getIdPart())); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Resource contains reference to Organization/testCreateWithIllegalReference but resource with ID testCreateWithIllegalReference is actually of type Observation", e.getMessage()); @@ -497,7 +498,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); o1.setValue(new CodeableConceptDt("testChoiceParam01CCS", "testChoiceParam01CCV")); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_CONCEPT, new TokenParam("testChoiceParam01CCS", "testChoiceParam01CCV")); @@ -512,7 +513,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01"); patient.setManagingOrganization(new ResourceReferenceDt("Patient/99999999")); try { - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), StringContains.containsString("99999 not found")); @@ -527,7 +528,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.getManagingOrganization().setReference("Organization/"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Does not contain resource ID")); @@ -541,7 +542,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.getManagingOrganization().setReference("Blah/123"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Invalid resource reference")); @@ -555,7 +556,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.getManagingOrganization().setReference("123"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Does not contain resource type")); @@ -568,7 +569,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Encounter enc = new Encounter(); enc.addIdentifier().setSystem("testDatePeriodParam").setValue("02"); enc.getPeriod().getEndElement().setValueAsString("2001-01-02"); - myEncounterDao.create(enc); + myEncounterDao.create(enc, new ServletRequestDetails()); } SearchParameterMap params; List encs; @@ -612,7 +613,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { enc.addIdentifier().setSystem("testDatePeriodParam").setValue("03"); enc.getPeriod().getStartElement().setValueAsString("2001-01-02"); enc.getPeriod().getEndElement().setValueAsString("2001-01-03"); - myEncounterDao.create(enc); + myEncounterDao.create(enc, new ServletRequestDetails()); } SearchParameterMap params = new SearchParameterMap(); @@ -665,7 +666,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Encounter enc = new Encounter(); enc.addIdentifier().setSystem("testDatePeriodParam").setValue("01"); enc.getPeriod().getStartElement().setValueAsString("2001-01-02"); - myEncounterDao.create(enc); + myEncounterDao.create(enc, new ServletRequestDetails()); } SearchParameterMap params = new SearchParameterMap(); @@ -705,12 +706,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String methodName = "testDeleteFailsIfIncomingLinks"; Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient patient = new Patient(); patient.addName().addFamily(methodName); patient.getManagingOrganization().setReference(orgId); - IIdType patId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map = new SearchParameterMap(); map.add("_id", new StringParam(orgId.getIdPart())); @@ -719,13 +720,13 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertThat(found, contains(orgId, patId)); try { - myOrganizationDao.delete(orgId); + myOrganizationDao.delete(orgId, new ServletRequestDetails()); fail(); } catch (ResourceVersionConflictException e) { assertThat(e.getMessage(), containsString("Delete failed because of constraint")); } - myPatientDao.delete(patId); + myPatientDao.delete(patId, new ServletRequestDetails()); map = new SearchParameterMap(); map.add("_id", new StringParam(orgId.getIdPart())); @@ -733,7 +734,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { found = toUnqualifiedVersionlessIds(myOrganizationDao.search(map)); assertThat(found, contains(orgId)); - myOrganizationDao.delete(orgId); + myOrganizationDao.delete(orgId, new ServletRequestDetails()); map = new SearchParameterMap(); map.add("_id", new StringParam(orgId.getIdPart())); @@ -745,7 +746,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { @Test public void testDeleteResource() { - int initialHistory = myPatientDao.history(null).size(); + int initialHistory = myPatientDao.history(null, new ServletRequestDetails()).size(); IIdType id1; IIdType id2; @@ -754,18 +755,18 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testDeleteResource").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_testDeleteResource").addGiven("John"); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { - Patient patient = myPatientDao.read(id2); + Patient patient = myPatientDao.read(id2, new ServletRequestDetails()); patient.addIdentifier().setSystem("ZZZZZZZ").setValue("ZZZZZZZZZ"); - id2b = myPatientDao.update(patient).getId(); + id2b = myPatientDao.update(patient, new ServletRequestDetails()).getId(); } ourLog.info("ID1:{} ID2:{} ID2b:{}", new Object[] { id1, id2, id2b }); @@ -774,32 +775,32 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { List patients = toList(myPatientDao.search(params)); assertEquals(2, patients.size()); - myPatientDao.delete(id1); + myPatientDao.delete(id1, new ServletRequestDetails()); patients = toList(myPatientDao.search(params)); assertEquals(1, patients.size()); - myPatientDao.read(id1); + myPatientDao.read(id1, new ServletRequestDetails()); try { - myPatientDao.read(id1.toVersionless()); + myPatientDao.read(id1.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } - IBundleProvider history = myPatientDao.history(null); + IBundleProvider history = myPatientDao.history(null, new ServletRequestDetails()); assertEquals(4 + initialHistory, history.size()); List resources = history.getResources(0, 4); assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IResource) resources.get(0))); try { - myPatientDao.delete(id2); + myPatientDao.delete(id2, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { // good } - myPatientDao.delete(id2.toVersionless()); + myPatientDao.delete(id2.toVersionless(), new ServletRequestDetails()); patients = toList(myPatientDao.search(params)); assertEquals(0, patients.size()); @@ -811,17 +812,17 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testDeleteThenUndelete").addGiven("Joe"); - IIdType id = myPatientDao.create(patient).getId(); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId(); assertThat(id.getValue(), Matchers.endsWith("/_history/1")); // should be ok - myPatientDao.read(id.toUnqualifiedVersionless()); + myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()); // Delete it - myPatientDao.delete(id.toUnqualifiedVersionless()); + myPatientDao.delete(id.toUnqualifiedVersionless(), new ServletRequestDetails()); try { - myPatientDao.read(id.toUnqualifiedVersionless()); + myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // expected @@ -831,11 +832,11 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testDeleteThenUndelete").addGiven("Joe"); patient.setId(id.toUnqualifiedVersionless()); - IIdType id2 = myPatientDao.update(patient).getId(); + IIdType id2 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); assertThat(id2.getValue(), endsWith("/_history/3")); - IIdType gotId = myPatientDao.read(id.toUnqualifiedVersionless()).getId(); + IIdType gotId = myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()).getId(); assertEquals(id2, gotId); } @@ -845,16 +846,16 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReference(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization.name=" + methodName); + myPatientDao.deleteByUrl("Patient?organization.name=" + methodName, new ServletRequestDetails()); assertGone(id); } @@ -867,20 +868,20 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Organization org = new Organization(); org.setName(methodName); org.addIdentifier().setSystem("http://example.com").setValue(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReference(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization.identifier=http://example.com|" + methodName); + myPatientDao.deleteByUrl("Patient?organization.identifier=http://example.com|" + methodName, new ServletRequestDetails()); assertGone(id); assertNotGone(orgId); - myOrganizationDao.deleteByUrl("Organization?identifier=http://example.com|" + methodName); + myOrganizationDao.deleteByUrl("Organization?identifier=http://example.com|" + methodName, new ServletRequestDetails()); assertGone(id); assertGone(orgId); @@ -898,35 +899,35 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { ResourceMetadataKeyEnum.TAG_LIST.put(org, tl); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReference(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization._tag=http://foo|term"); + myPatientDao.deleteByUrl("Patient?organization._tag=http://foo|term", new ServletRequestDetails()); assertGone(id); - myOrganizationDao.deleteByUrl("Organization?_tag=http://foo|term"); + myOrganizationDao.deleteByUrl("Organization?_tag=http://foo|term", new ServletRequestDetails()); try { - myOrganizationDao.read(orgId); + myOrganizationDao.read(orgId, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myPatientDao.deleteByUrl("Patient?organization._tag.identifier=http://foo|term"); + myPatientDao.deleteByUrl("Patient?organization._tag.identifier=http://foo|term", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: organization._tag.identifier", e.getMessage()); } try { - myOrganizationDao.deleteByUrl("Organization?_tag.identifier=http://foo|term"); + myOrganizationDao.deleteByUrl("Organization?_tag.identifier=http://foo|term", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: _tag.identifier", e.getMessage()); @@ -945,12 +946,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Organization org1 = new Organization(); org1.addIdentifier().setValue(methodName); - IIdType org1Id = myOrganizationDao.create(org1).getId().toUnqualifiedVersionless(); + IIdType org1Id = myOrganizationDao.create(org1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); p1.getManagingOrganization().setReference(org1Id); - IIdType patId1 = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + IIdType patId1 = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); /* * Org 2 has a name @@ -959,37 +960,37 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Organization org2 = new Organization(); org2.setName(methodName); org2.addIdentifier().setValue(methodName); - IIdType org2Id = myOrganizationDao.create(org2).getId().toUnqualifiedVersionless(); + IIdType org2Id = myOrganizationDao.create(org2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue(methodName); p2.getManagingOrganization().setReference(org2Id); - IIdType patId2 = myPatientDao.create(p2).getId().toUnqualifiedVersionless(); + IIdType patId2 = myPatientDao.create(p2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Pat ID 1 : {}", patId1); ourLog.info("Org ID 1 : {}", org1Id); ourLog.info("Pat ID 2 : {}", patId2); ourLog.info("Org ID 2 : {}", org2Id); - myPatientDao.deleteByUrl("Patient?organization.name:missing=true"); + myPatientDao.deleteByUrl("Patient?organization.name:missing=true", new ServletRequestDetails()); assertGone(patId1); assertNotGone(patId2); assertNotGone(org1Id); assertNotGone(org2Id); - myOrganizationDao.deleteByUrl("Organization?name:missing=true"); + myOrganizationDao.deleteByUrl("Organization?name:missing=true", new ServletRequestDetails()); assertGone(patId1); assertNotGone(patId2); assertGone(org1Id); assertNotGone(org2Id); - myPatientDao.deleteByUrl("Patient?organization.name:missing=false"); + myPatientDao.deleteByUrl("Patient?organization.name:missing=false", new ServletRequestDetails()); assertGone(patId1); assertGone(patId2); assertGone(org1Id); assertNotGone(org2Id); - myOrganizationDao.deleteByUrl("Organization?name:missing=false"); + myOrganizationDao.deleteByUrl("Organization?name:missing=false", new ServletRequestDetails()); assertGone(patId1); assertGone(patId2); assertGone(org1Id); @@ -1001,9 +1002,9 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { */ private void assertNotGone(IIdType theId) { if ("Patient".equals(theId.getResourceType())) { - myPatientDao.read(theId); + myPatientDao.read(theId, new ServletRequestDetails()); } else if ("Organization".equals(theId.getResourceType())){ - myOrganizationDao.read(theId); + myOrganizationDao.read(theId, new ServletRequestDetails()); } else { fail("No type"); } @@ -1030,35 +1031,35 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { ResourceMetadataKeyEnum.PROFILES.put(org, profileList); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReference(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization._profile=http://foo"); + myPatientDao.deleteByUrl("Patient?organization._profile=http://foo", new ServletRequestDetails()); assertGone(id); - myOrganizationDao.deleteByUrl("Organization?_profile=http://foo"); + myOrganizationDao.deleteByUrl("Organization?_profile=http://foo", new ServletRequestDetails()); try { - myOrganizationDao.read(orgId); + myOrganizationDao.read(orgId, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myPatientDao.deleteByUrl("Patient?organization._profile.identifier=http://foo"); + myPatientDao.deleteByUrl("Patient?organization._profile.identifier=http://foo", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: organization._profile.identifier", e.getMessage()); } try { - myOrganizationDao.deleteByUrl("Organization?_profile.identifier=http://foo"); + myOrganizationDao.deleteByUrl("Organization?_profile.identifier=http://foo", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: _profile.identifier", e.getMessage()); @@ -1072,29 +1073,29 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); request.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.DELETE).setUrl("Patient?identifier=urn%3Asystem%7C" + methodName); - myPatientDao.deleteByUrl("Patient?identifier=urn%3Asystem%7C" + methodName); + myPatientDao.deleteByUrl("Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); try { - myPatientDao.read(id.toVersionless()); + myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // ok } try { - myPatientDao.read(new IdDt("Patient/" + methodName)); + myPatientDao.read(new IdDt("Patient/" + methodName), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // ok } - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(2, history.size()); assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IResource) history.getResources(0, 0).get(0))); @@ -1112,14 +1113,14 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("testHistoryByForcedId"); patient.addName().addFamily("Tester").addGiven("testHistoryByForcedId"); patient.setId("Patient/testHistoryByForcedId"); - idv1 = myPatientDao.update(patient).getId(); + idv1 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); patient.addName().addFamily("Tester").addGiven("testHistoryByForcedIdName2"); patient.setId(patient.getId().toUnqualifiedVersionless()); - idv2 = myPatientDao.update(patient).getId(); + idv2 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); } - List patients = toList(myPatientDao.history(idv1.toVersionless(), null)); + List patients = toList(myPatientDao.history(idv1.toVersionless(), null, new ServletRequestDetails())); assertTrue(patients.size() == 2); // Newest first assertEquals("Patient/testHistoryByForcedId/_history/2", patients.get(0).getId().toUnqualified().getValue()); @@ -1141,7 +1142,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addName().addFamily(methodName); - IIdType id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Date middleDate = null; int halfSize = 50; @@ -1154,11 +1155,11 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } patient.setId(id); patient.getName().get(0).getFamily().get(0).setValue(methodName + "_i"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); } // By instance - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1167,7 +1168,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } // By type - history = myPatientDao.history(null); + history = myPatientDao.history(null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1176,7 +1177,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } // By server - history = mySystemDao.history(null); + history = mySystemDao.history(null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1189,7 +1190,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { */ // By instance - history = myPatientDao.history(id, middleDate); + history = myPatientDao.history(id, middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1198,7 +1199,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } // By type - history = myPatientDao.history(middleDate); + history = myPatientDao.history(middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1207,7 +1208,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } // By server - history = mySystemDao.history(middleDate); + history = mySystemDao.history(middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1219,13 +1220,13 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { * Now delete the most recent version and make sure everything still works */ - myPatientDao.delete(id.toVersionless()); + myPatientDao.delete(id.toVersionless(), new ServletRequestDetails()); fullSize++; halfSize++; // By instance - history = myPatientDao.history(id, null); + history = myPatientDao.history(id, null, new ServletRequestDetails()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); @@ -1234,7 +1235,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals(log(history), fullSize + 1, history.size()); // By type - history = myPatientDao.history(null); + history = myPatientDao.history(null, new ServletRequestDetails()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); @@ -1245,7 +1246,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals(log(history), fullSize + 1, history.size()); // fails? // By server - history = mySystemDao.history(null); + history = mySystemDao.history(null, new ServletRequestDetails()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); @@ -1258,7 +1259,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { */ // By instance - history = myPatientDao.history(id, middleDate); + history = myPatientDao.history(id, middleDate, new ServletRequestDetails()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); @@ -1267,7 +1268,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals(halfSize, history.size()); // By type - history = myPatientDao.history(middleDate); + history = myPatientDao.history(middleDate, new ServletRequestDetails()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); @@ -1276,7 +1277,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals(halfSize, history.size()); // By server - history = mySystemDao.history(middleDate); + history = mySystemDao.history(middleDate, new ServletRequestDetails()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); @@ -1300,13 +1301,13 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addName().addFamily(methodName); - IIdType id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); - myPatientDao.delete(id); + myPatientDao.delete(id, new ServletRequestDetails()); patient.setId(id); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(3, history.size()); List entries = history.getResources(0, 3); ourLog.info("" + ResourceMetadataKeyEnum.UPDATED.get((IResource) entries.get(0))); @@ -1333,14 +1334,14 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester").addGiven("Joe"); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); assertNotNull(outcome.getId()); assertFalse(outcome.getId().isEmpty()); Date now = new Date(); { - Patient retrieved = myPatientDao.read(outcome.getId()); + Patient retrieved = myPatientDao.read(outcome.getId(), new ServletRequestDetails()); InstantDt published = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED); InstantDt updated = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED); assertTrue(published.before(now)); @@ -1351,13 +1352,13 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { * This ID points to a patient, so we should not be able to return othe types with it */ try { - myEncounterDao.read(outcome.getId()); + myEncounterDao.read(outcome.getId(), new ServletRequestDetails()); fail(); } catch (IllegalArgumentException e) { // expected } try { - myEncounterDao.read(new IdDt(outcome.getId().getIdPart())); + myEncounterDao.read(new IdDt(outcome.getId().getIdPart()), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // expected @@ -1421,7 +1422,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/2")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - id = myPatientDao.create(patient).getId(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } assertTrue(id.hasVersionIdPart()); @@ -1430,9 +1431,9 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { * Create a second version */ - Patient pt = myPatientDao.read(id); + Patient pt = myPatientDao.read(id, new ServletRequestDetails()); pt.addName().addFamily("anotherName"); - myPatientDao.update(pt); + myPatientDao.update(pt, new ServletRequestDetails()); /* * Meta-Delete on previous version @@ -1442,7 +1443,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - MetaDt newMeta = myPatientDao.metaDeleteOperation(id.withVersion("1"), meta); + MetaDt newMeta = myPatientDao.metaDeleteOperation(id.withVersion("1"), meta, new ServletRequestDetails()); assertEquals(1, newMeta.getProfile().size()); assertEquals(1, newMeta.getSecurity().size()); assertEquals(1, newMeta.getTag().size()); @@ -1454,7 +1455,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { * Meta Read on Version */ - meta = myPatientDao.metaGetOperation(MetaDt.class, id.withVersion("1")); + meta = myPatientDao.metaGetOperation(MetaDt.class, id.withVersion("1"), new ServletRequestDetails()); assertEquals(1, meta.getProfile().size()); assertEquals(1, meta.getSecurity().size()); assertEquals(1, meta.getTag().size()); @@ -1465,7 +1466,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { /* * Meta-read on Version 2 */ - meta = myPatientDao.metaGetOperation(MetaDt.class, id.withVersion("2")); + meta = myPatientDao.metaGetOperation(MetaDt.class, id.withVersion("2"), new ServletRequestDetails()); assertEquals(2, meta.getProfile().size()); assertEquals(2, meta.getSecurity().size()); assertEquals(2, meta.getTag().size()); @@ -1473,7 +1474,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { /* * Meta-read on latest version */ - meta = myPatientDao.metaGetOperation(MetaDt.class, id.toVersionless()); + meta = myPatientDao.metaGetOperation(MetaDt.class, id.toVersionless(), new ServletRequestDetails()); assertEquals(2, meta.getProfile().size()); assertEquals(2, meta.getSecurity().size()); assertEquals(2, meta.getTag().size()); @@ -1487,7 +1488,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - newMeta = myPatientDao.metaAddOperation(id.withVersion("1"), meta); + newMeta = myPatientDao.metaAddOperation(id.withVersion("1"), meta, new ServletRequestDetails()); assertEquals(2, newMeta.getProfile().size()); assertEquals(2, newMeta.getSecurity().size()); assertEquals(2, newMeta.getTag().size()); @@ -1496,7 +1497,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { * Meta Read on Version */ - meta = myPatientDao.metaGetOperation(MetaDt.class, id.withVersion("1")); + meta = myPatientDao.metaGetOperation(MetaDt.class, id.withVersion("1"), new ServletRequestDetails()); assertEquals(2, meta.getProfile().size()); assertEquals(2, meta.getSecurity().size()); assertEquals(2, meta.getTag().size()); @@ -1510,7 +1511,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - newMeta = myPatientDao.metaDeleteOperation(id.toVersionless(), meta); + newMeta = myPatientDao.metaDeleteOperation(id.toVersionless(), meta, new ServletRequestDetails()); assertEquals(1, newMeta.getProfile().size()); assertEquals(1, newMeta.getSecurity().size()); assertEquals(1, newMeta.getTag().size()); @@ -1526,7 +1527,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - newMeta = myPatientDao.metaAddOperation(id.toVersionless(), meta); + newMeta = myPatientDao.metaAddOperation(id.toVersionless(), meta, new ServletRequestDetails()); assertEquals(2, newMeta.getProfile().size()); assertEquals(2, newMeta.getSecurity().size()); assertEquals(2, newMeta.getTag().size()); @@ -1611,7 +1612,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { int initial = val.size(); Organization org = myFhirCtx.newJsonParser().parseResource(Organization.class, inputStr); - myOrganizationDao.create(org); + myOrganizationDao.create(org, new ServletRequestDetails()); val = myOrganizationDao.searchForIds("name", new StringParam("P")); assertEquals(initial + 1, val.size()); @@ -1626,7 +1627,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testPersistContactPoint"); patient.addTelecom().setValue("555-123-4567"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); found = toList(myPatientDao.search(Patient.SP_TELECOM, new TokenParam(null, "555-123-4567"))); assertEquals(1 + initialSize2000, found.size()); @@ -1637,26 +1638,26 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testPersistResourceLink() { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testPersistResourceLink01"); - IIdType patientId01 = myPatientDao.create(patient).getId(); + IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Patient patient02 = new Patient(); patient02.addIdentifier().setSystem("urn:system").setValue("testPersistResourceLink02"); - IIdType patientId02 = myPatientDao.create(patient02).getId(); + IIdType patientId02 = myPatientDao.create(patient02, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeDt(new Date())); obs01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeDt(new Date())); obs02.setSubject(new ResourceReferenceDt(patientId02)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); // Create another type, that shouldn't be returned DiagnosticReport dr01 = new DiagnosticReport(); dr01.setSubject(new ResourceReferenceDt(patientId01)); - IIdType drId01 = myDiagnosticReportDao.create(dr01).getId(); + IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 }); @@ -1685,7 +1686,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.setBirthDate(new DateDt("2001-01-01")); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); found = toList(myPatientDao.search(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"))); assertEquals(1 + initialSize2000, found.size()); @@ -1705,7 +1706,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { obs.getCode().addCoding().setSystem("foo").setCode("testPersistSearchParamQuantity"); obs.setValue(new StringDt("AAAABBBB")); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); List found = toList(myObservationDao.search("value-string", new StringDt("AAAABBBB"))); assertEquals(1, found.size()); @@ -1721,7 +1722,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { obs.getCode().addCoding().setSystem("foo").setCode("testPersistSearchParamQuantity"); obs.setValue(new QuantityDt(111)); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); List found = toList(myObservationDao.search("value-quantity", new QuantityDt(111))); assertEquals(1, found.size()); @@ -1741,7 +1742,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { patient.getGenderElement().setValueAsEnum(AdministrativeGenderEnum.MALE); patient.addName().addFamily("Tester").addGiven("JoetestPersistSearchParams"); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); assertNotNull(outcome.getId()); assertFalse(outcome.getId().isEmpty()); @@ -1786,10 +1787,10 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testQuestionnaireTitleGetsIndexed() { Questionnaire q = new Questionnaire(); q.getGroup().setTitle("testQuestionnaireTitleGetsIndexedQ_TITLE"); - IIdType qid1 = myQuestionnaireDao.create(q).getId().toUnqualifiedVersionless(); + IIdType qid1 = myQuestionnaireDao.create(q, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); q = new Questionnaire(); q.getGroup().setTitle("testQuestionnaireTitleGetsIndexedQ_NOTITLE"); - IIdType qid2 = myQuestionnaireDao.create(q).getId().toUnqualifiedVersionless(); + IIdType qid2 = myQuestionnaireDao.create(q, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider results = myQuestionnaireDao.search("title", new StringParam("testQuestionnaireTitleGetsIndexedQ_TITLE")); assertEquals(1, results.size()); @@ -1802,14 +1803,14 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testRead() { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testRead"); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); /* * READ */ reset(myInterceptor); - Observation obs = myObservationDao.read(id1.toUnqualifiedVersionless()); + Observation obs = myObservationDao.read(id1.toUnqualifiedVersionless(), new ServletRequestDetails()); assertEquals(o1.getCode().getCoding().get(0).getCode(), obs.getCode().getCoding().get(0).getCode()); // Verify interceptor @@ -1824,7 +1825,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { */ assertTrue(id1.hasVersionIdPart()); // just to make sure.. reset(myInterceptor); - obs = myObservationDao.read(id1); + obs = myObservationDao.read(id1, new ServletRequestDetails()); assertEquals(o1.getCode().getCoding().get(0).getCode(), obs.getCode().getCoding().get(0).getCode()); // Verify interceptor @@ -1841,20 +1842,20 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testReadVorcedIdVersionHistory01"); p1.setId("testReadVorcedIdVersionHistory"); - IIdType p1id = myPatientDao.update(p1).getId(); + IIdType p1id = myPatientDao.update(p1, new ServletRequestDetails()).getId(); assertEquals("testReadVorcedIdVersionHistory", p1id.getIdPart()); p1.addIdentifier().setSystem("urn:system").setValue("testReadVorcedIdVersionHistory02"); p1.setId(p1id); - IIdType p1idv2 = myPatientDao.update(p1).getId(); + IIdType p1idv2 = myPatientDao.update(p1, new ServletRequestDetails()).getId(); assertEquals("testReadVorcedIdVersionHistory", p1idv2.getIdPart()); assertNotEquals(p1id.getValue(), p1idv2.getValue()); - Patient v1 = myPatientDao.read(p1id); + Patient v1 = myPatientDao.read(p1id, new ServletRequestDetails()); assertEquals(1, v1.getIdentifier().size()); - Patient v2 = myPatientDao.read(p1idv2); + Patient v2 = myPatientDao.read(p1idv2, new ServletRequestDetails()); assertEquals(2, v2.getIdentifier().size()); } @@ -1865,33 +1866,33 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient pat = new Patient(); pat.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(pat).getId(); + IIdType id = myPatientDao.create(pat, new ServletRequestDetails()).getId(); - assertEquals(methodName, myPatientDao.read(id).getIdentifier().get(0).getValue()); + assertEquals(methodName, myPatientDao.read(id, new ServletRequestDetails()).getIdentifier().get(0).getValue()); try { - myPatientDao.read(id.withVersion("0")); + myPatientDao.read(id.withVersion("0"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Version \"0\" is not valid for resource Patient/" + id.getIdPart(), e.getMessage()); } try { - myPatientDao.read(id.withVersion("2")); + myPatientDao.read(id.withVersion("2"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Version \"2\" is not valid for resource Patient/" + id.getIdPart(), e.getMessage()); } try { - myPatientDao.read(id.withVersion("H")); + myPatientDao.read(id.withVersion("H"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Version \"H\" is not valid for resource Patient/" + id.getIdPart(), e.getMessage()); } try { - myPatientDao.read(new IdDt("Patient/9999999999999/_history/1")); + myPatientDao.read(new IdDt("Patient/9999999999999/_history/1"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Resource Patient/9999999999999/_history/1 is not known", e.getMessage()); @@ -1905,31 +1906,31 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addName().addFamily(methodName); - IIdType id = myPatientDao.create(patient).getId().toVersionless(); - myPatientDao.delete(id); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toVersionless(); + myPatientDao.delete(id, new ServletRequestDetails()); assertGone(id); patient.setId(id); patient.addAddress().addLine("AAA"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); Patient p; - p = myPatientDao.read(id); + p = myPatientDao.read(id, new ServletRequestDetails()); assertEquals(1, (p).getName().size()); - p = myPatientDao.read(id.withVersion("1")); + p = myPatientDao.read(id.withVersion("1"), new ServletRequestDetails()); assertEquals(1, (p).getName().size()); try { - myPatientDao.read(id.withVersion("2")); + myPatientDao.read(id.withVersion("2"), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } - p = myPatientDao.read(id.withVersion("3")); + p = myPatientDao.read(id.withVersion("3"), new ServletRequestDetails()); assertEquals(1, (p).getName().size()); } @@ -1942,13 +1943,13 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue(methodName); patient.addName().addFamily("Tester").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); MetaDt metaAdd = new MetaDt(); metaAdd.addTag().setSystem((String) null).setCode("Dog").setDisplay("Puppies"); metaAdd.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"); metaAdd.addProfile("http://profile/1"); - myPatientDao.metaAddOperation(id1, metaAdd); + myPatientDao.metaAddOperation(id1, metaAdd, new ServletRequestDetails()); } { Patient patient = new Patient(); @@ -1966,7 +1967,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/2")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Device device = new Device(); @@ -1983,12 +1984,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/3")); ResourceMetadataKeyEnum.PROFILES.put(device, profiles); - myDeviceDao.create(device); + myDeviceDao.create(device, new ServletRequestDetails()); } MetaDt meta; - meta = myPatientDao.metaGetOperation(MetaDt.class); + meta = myPatientDao.metaGetOperation(MetaDt.class, new ServletRequestDetails()); List published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); @@ -2010,7 +2011,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals("http://profile/1", profiles.get(0).getValue()); assertEquals("http://profile/2", profiles.get(1).getValue()); - meta = myPatientDao.metaGetOperation(MetaDt.class, id2); + meta = myPatientDao.metaGetOperation(MetaDt.class, id2, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2030,10 +2031,10 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { metaDel.addTag().setSystem((String) null).setCode("Dog"); metaDel.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1"); metaDel.addProfile("http://profile/1"); - myPatientDao.metaDeleteOperation(id1, metaDel); + myPatientDao.metaDeleteOperation(id1, metaDel, new ServletRequestDetails()); } - meta = myPatientDao.metaGetOperation(MetaDt.class); + meta = myPatientDao.metaGetOperation(MetaDt.class, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2071,7 +2072,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/1")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); @@ -2089,7 +2090,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/2")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Device device = new Device(); @@ -2106,12 +2107,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/3")); ResourceMetadataKeyEnum.PROFILES.put(device, profiles); - myDeviceDao.create(device); + myDeviceDao.create(device, new ServletRequestDetails()); } MetaDt meta; - meta = myPatientDao.metaGetOperation(MetaDt.class); + meta = myPatientDao.metaGetOperation(MetaDt.class, new ServletRequestDetails()); List published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); @@ -2133,7 +2134,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals("http://profile/1", profiles.get(0).getValue()); assertEquals("http://profile/2", profiles.get(1).getValue()); - meta = myPatientDao.metaGetOperation(MetaDt.class, id2); + meta = myPatientDao.metaGetOperation(MetaDt.class, id2, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2148,11 +2149,11 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertEquals(1, profiles.size()); assertEquals("http://profile/2", profiles.get(0).getValue()); - myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog"); - myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1"); - myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1"); + myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1", new ServletRequestDetails()); - meta = myPatientDao.metaGetOperation(MetaDt.class); + meta = myPatientDao.metaGetOperation(MetaDt.class, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2174,12 +2175,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String methodName = "testReverseIncludes"; Organization org = new Organization(); org.setName("X" + methodName + "X"); - IIdType orgId = myOrganizationDao.create(org).getId(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId(); Patient pat = new Patient(); pat.addName().addFamily("X" + methodName + "X"); pat.getManagingOrganization().setReference(orgId.toUnqualifiedVersionless()); - myPatientDao.create(pat); + myPatientDao.create(pat, new ServletRequestDetails()); SearchParameterMap map = new SearchParameterMap(); map.add(Organization.SP_NAME, new StringParam("X" + methodName + "X")); @@ -2199,7 +2200,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testSortByComposite() { Observation o = new Observation(); o.getCode().setText("testSortByComposite"); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); SearchParameterMap pm = new SearchParameterMap(); pm.setSort(new SortSpec(Observation.SP_CODE_VALUE_CONCEPT)); @@ -2217,24 +2218,24 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); p.addName().addFamily("testSortF1").addGiven("testSortG1"); p.setBirthDate(new DateDt("2001-01-01")); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); // Create out of order p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); p.addName().addFamily("testSortF2").addGiven("testSortG2"); p.setBirthDate(new DateDt("2001-01-03")); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); p.addName().addFamily("testSortF3").addGiven("testSortG3"); p.setBirthDate(new DateDt("2001-01-02")); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual; SearchParameterMap pm; @@ -2269,22 +2270,22 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system1").setValue(methodName); p.addName().addFamily(methodName); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName); p.addName().addFamily(methodName); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system3").setValue(methodName); p.addName().addFamily(methodName); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system4").setValue(methodName); p.addName().addFamily(methodName); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2317,7 +2318,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map; @@ -2341,25 +2342,25 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.setId(methodName); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType idMethodName = myPatientDao.update(p).getId().toUnqualifiedVersionless(); + IIdType idMethodName = myPatientDao.update(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertEquals(methodName, idMethodName.getIdPart()); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2393,17 +2394,17 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Encounter e1 = new Encounter(); e1.addIdentifier().setSystem("foo").setValue(methodName); e1.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60); - IIdType id1 = myEncounterDao.create(e1).getId().toUnqualifiedVersionless(); + IIdType id1 = myEncounterDao.create(e1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Encounter e3 = new Encounter(); e3.addIdentifier().setSystem("foo").setValue(methodName); e3.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(3.0); - IIdType id3 = myEncounterDao.create(e3).getId().toUnqualifiedVersionless(); + IIdType id3 = myEncounterDao.create(e3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Encounter e2 = new Encounter(); e2.addIdentifier().setSystem("foo").setValue(methodName); e2.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(2.0); - IIdType id2 = myEncounterDao.create(e2).getId().toUnqualifiedVersionless(); + IIdType id2 = myEncounterDao.create(e2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2424,19 +2425,19 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { res = new Observation(); res.setValue(new QuantityDt().setSystem("sys1").setCode("code1").setValue(2L)); - IIdType id2 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new Observation(); res.setValue(new QuantityDt().setSystem("sys1").setCode("code1").setValue(1L)); - IIdType id1 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new Observation(); res.setValue(new QuantityDt().setSystem("sys1").setCode("code1").setValue(3L)); - IIdType id3 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id3 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new Observation(); res.setValue(new QuantityDt().setSystem("sys1").setCode("code1").setValue(4L)); - IIdType id4 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id4 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm = new SearchParameterMap(); pm.setSort(new SortSpec(Observation.SP_VALUE_QUANTITY)); @@ -2463,33 +2464,33 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String methodName = "testSortByReference"; Organization o1 = new Organization(); - IIdType oid1 = myOrganizationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType oid1 = myOrganizationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Organization o2 = new Organization(); - IIdType oid2 = myOrganizationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType oid2 = myOrganizationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("testSortF1").addGiven("testSortG1"); p.getManagingOrganization().setReference(oid1); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("testSortF2").addGiven("testSortG2"); p.getManagingOrganization().setReference(oid2); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("testSortF3").addGiven("testSortG3"); p.getManagingOrganization().setReference(oid1); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReference(oid2); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2525,22 +2526,22 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String string = "testSortByString01"; p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("testSortF1").addGiven("testSortG1"); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); // Create out of order p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("testSortF3").addGiven("testSortG3"); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("testSortF2").addGiven("testSortG2"); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2578,22 +2579,22 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam1").addGiven("Giv1"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam2").addGiven("Giv1"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam2").addGiven("Giv2"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam1").addGiven("Giv2"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List names; @@ -2639,19 +2640,19 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName + "1"); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system1").setValue(methodName + "2"); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system1").setValue(methodName + "1"); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName + "2"); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2685,19 +2686,19 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testSortByUri() { ConceptMap res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://foo2"); - IIdType id2 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id2 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://foo1"); - IIdType id1 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id1 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://bar3"); - IIdType id3 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id3 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://bar4"); - IIdType id4 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id4 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm = new SearchParameterMap(); pm.setSort(new SortSpec(ConceptMap.SP_DEPENDSON)); @@ -2717,15 +2718,15 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { public void testStoreUnversionedResources() { Organization o1 = new Organization(); o1.getNameElement().setValue("AAA"); - IIdType o1id = myOrganizationDao.create(o1).getId(); + IIdType o1id = myOrganizationDao.create(o1, new ServletRequestDetails()).getId(); assertTrue(o1id.hasVersionIdPart()); Patient p1 = new Patient(); p1.addName().addFamily("AAAA"); p1.getManagingOrganization().setReference(o1id); - IIdType p1id = myPatientDao.create(p1).getId(); + IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId(); - p1 = myPatientDao.read(p1id); + p1 = myPatientDao.read(p1id, new ServletRequestDetails()); assertFalse(p1.getManagingOrganization().getReference().hasVersionIdPart()); assertEquals(o1id.toUnqualifiedVersionless(), p1.getManagingOrganization().getReference().toUnqualifiedVersionless()); @@ -2739,9 +2740,9 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Organization org = new Organization(); org.setName("測試醫院"); org.addIdentifier().setSystem("urn:system").setValue("testStoreUtf8Characters_01"); - IIdType orgId = myOrganizationDao.create(org).getId(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId(); - Organization returned = myOrganizationDao.read(orgId); + Organization returned = myOrganizationDao.read(orgId, new ServletRequestDetails()); String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); @@ -2761,7 +2762,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Set val = myOrganizationDao.searchForIds("name", new StringParam("P")); int initial = val.size(); - myOrganizationDao.create(org); + myOrganizationDao.create(org, new ServletRequestDetails()); val = myOrganizationDao.searchForIds("name", new StringParam("P")); assertEquals(initial + 0, val.size()); @@ -2799,12 +2800,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { profiles.add(new IdDt("http://profile/2")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); IIdType patientId = outcome.getId(); assertNotNull(patientId); assertFalse(patientId.isEmpty()); - Patient retrieved = myPatientDao.read(patientId); + Patient retrieved = myPatientDao.read(patientId, new ServletRequestDetails()); TagList published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST); sort(published); assertEquals(2, published.size()); @@ -2862,7 +2863,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { myPatientDao.addTag(patientId, TagTypeEnum.TAG, "http://foo", "Cat", "Kittens"); myPatientDao.addTag(patientId, TagTypeEnum.TAG, "http://foo", "Cow", "Calves"); - retrieved = myPatientDao.read(patientId); + retrieved = myPatientDao.read(patientId, new ServletRequestDetails()); published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST); sort(published); assertEquals(3, published.size()); @@ -2909,7 +2910,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { Set val = myOrganizationDao.searchForIds("type", new IdentifierDt(subStr1, subStr2)); int initial = val.size(); - myOrganizationDao.create(org); + myOrganizationDao.create(org, new ServletRequestDetails()); val = myOrganizationDao.searchForIds("type", new IdentifierDt(subStr1, subStr2)); assertEquals(initial + 1, val.size()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java index 8c66d682281..c6f4272a04d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java @@ -44,6 +44,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2UpdateTest.class); @@ -54,14 +55,14 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester").addGiven("Joe"); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); assertNotNull(outcome.getId()); assertFalse(outcome.getId().isEmpty()); assertEquals("1", outcome.getId().getVersionIdPart()); Date now = new Date(); - Patient retrieved = myPatientDao.read(outcome.getId()); + Patient retrieved = myPatientDao.read(outcome.getId(), new ServletRequestDetails()); InstantDt published = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED); InstantDt updated = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED); assertTrue(published.before(now)); @@ -71,7 +72,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { reset(myInterceptor); retrieved.getIdentifierFirstRep().setValue("002"); - MethodOutcome outcome2 = myPatientDao.update(retrieved); + MethodOutcome outcome2 = myPatientDao.update(retrieved, new ServletRequestDetails()); assertEquals(outcome.getId().getIdPart(), outcome2.getId().getIdPart()); assertNotEquals(outcome.getId().getVersionIdPart(), outcome2.getId().getVersionIdPart()); assertEquals("2", outcome2.getId().getVersionIdPart()); @@ -86,7 +87,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { Date now2 = new Date(); - Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless()); + Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless(), new ServletRequestDetails()); assertEquals("2", retrieved2.getId().getVersionIdPart()); assertEquals("002", retrieved2.getIdentifierFirstRep().getValue()); @@ -102,7 +103,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { * Get history */ - IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null); + IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null, new ServletRequestDetails()); assertEquals(2, historyBundle.size()); @@ -125,7 +126,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -133,9 +134,9 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/" + methodName); - myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName); + myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); - p = myPatientDao.read(id.toVersionless()); + p = myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); assertThat(p.getId().toVersionless().toString(), not(containsString("test"))); assertEquals(id.toVersionless(), p.getId().toVersionless()); assertNotEquals(id, p.getId()); @@ -151,10 +152,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); assertEquals("Patient/" + methodName, id.toUnqualifiedVersionless().getValue()); - p = myPatientDao.read(id); + p = myPatientDao.read(id, new ServletRequestDetails()); assertEquals(methodName, p.getIdentifierFirstRep().getValue()); } @@ -165,7 +166,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.setId("0" + methodName); p.addName().addFamily(methodName); - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); } /** @@ -190,7 +191,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { profileList.add(new IdDt("http://foo1")); ResourceMetadataKeyEnum.PROFILES.put(p1, profileList); - p1id = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient p1 = new Patient(); @@ -207,10 +208,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { profileList.add(new IdDt("http://foo2")); ResourceMetadataKeyEnum.PROFILES.put(p1, profileList); - myPatientDao.update(p1); + myPatientDao.update(p1, new ServletRequestDetails()); } { - Patient p1 = myPatientDao.read(p1id); + Patient p1 = myPatientDao.read(p1id, new ServletRequestDetails()); TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(p1); assertThat(tagList, containsInAnyOrder(new Tag("tag_scheme1", "tag_term1"), new Tag("tag_scheme2", "tag_term2"))); List secList = ResourceMetadataKeyEnum.SECURITY_LABELS.get(p1); @@ -229,12 +230,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2AAA"); p1.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2AAA"); - IIdType p1id = myPatientDao.create(p1).getId(); + IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId(); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2BBB"); p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB"); - myPatientDao.create(p2).getId(); + myPatientDao.create(p2, new ServletRequestDetails()).getId(); Set ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA")); assertEquals(1, ids.size()); @@ -242,7 +243,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { // Update the name p1.getNameFirstRep().getGivenFirstRep().setValue("testUpdateMaintainsSearchParamsDstu2BBB"); - MethodOutcome update2 = myPatientDao.update(p1); + MethodOutcome update2 = myPatientDao.update(p1, new ServletRequestDetails()); IIdType p1id2 = update2.getId(); ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA")); @@ -252,10 +253,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { assertEquals(2, ids.size()); // Make sure vreads work - p1 = myPatientDao.read(p1id); + p1 = myPatientDao.read(p1id, new ServletRequestDetails()); assertEquals("testUpdateMaintainsSearchParamsDstu2AAA", p1.getNameFirstRep().getGivenAsSingleString()); - p1 = myPatientDao.read(p1id2); + p1 = myPatientDao.read(p1id2, new ServletRequestDetails()); assertEquals("testUpdateMaintainsSearchParamsDstu2BBB", p1.getNameFirstRep().getGivenAsSingleString()); } @@ -265,13 +266,13 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes"); p1.addName().addFamily("Tester").addGiven("testUpdateRejectsInvalidTypes"); - IIdType p1id = myPatientDao.create(p1).getId(); + IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId(); Organization p2 = new Organization(); p2.getNameElement().setValue("testUpdateRejectsInvalidTypes"); try { p2.setId(new IdDt("Organization/" + p1id.getIdPart())); - myOrganizationDao.update(p2); + myOrganizationDao.update(p2, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { // good @@ -279,7 +280,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { try { p2.setId(new IdDt("Patient/" + p1id.getIdPart())); - myOrganizationDao.update(p2); + myOrganizationDao.update(p2, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { ourLog.error("Good", e); @@ -301,12 +302,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { tl.add(new IdDt("http://foo/bar")); ResourceMetadataKeyEnum.PROFILES.put(patient, tl); - id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Do a read { - Patient patient = myPatientDao.read(id); + Patient patient = myPatientDao.read(id, new ServletRequestDetails()); List tl = ResourceMetadataKeyEnum.PROFILES.get(patient); assertEquals(1, tl.size()); assertEquals("http://foo/bar", tl.get(0).getValue()); @@ -326,12 +327,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { tl.add(new IdDt("http://foo/bar")); ResourceMetadataKeyEnum.PROFILES.put(patient, tl); - id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Do a read { - Patient patient = myPatientDao.read(id); + Patient patient = myPatientDao.read(id, new ServletRequestDetails()); List tl = ResourceMetadataKeyEnum.PROFILES.get(patient); assertEquals(1, tl.size()); assertEquals("http://foo/bar", tl.get(0).getValue()); @@ -347,12 +348,12 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { tl.add(new IdDt("http://foo/baz")); ResourceMetadataKeyEnum.PROFILES.put(patient, tl); - id = myPatientDao.update(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.update(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Do a read { - Patient patient = myPatientDao.read(id); + Patient patient = myPatientDao.read(id, new ServletRequestDetails()); List tl = ResourceMetadataKeyEnum.PROFILES.get(patient); assertEquals(1, tl.size()); assertEquals("http://foo/baz", tl.get(0).getValue()); @@ -367,7 +368,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/9999999999999999"); try { - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not create resource with ID[9999999999999999], no resource with this ID exists and clients may only")); @@ -381,7 +382,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/123:456"); try { - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Can not process entity with ID[123:456], this is not a valid FHIR ID", e.getMessage()); @@ -395,7 +396,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.addName().addFamily("Hello"); p.setId("Patient/123"); try { - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric")); @@ -408,11 +409,11 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p.addIdentifier().setSystem("urn:system").setValue("testCreateNumericIdFails"); p.addName().addFamily("Hello"); p.setId("Patient/123abc"); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); assertEquals("123abc", id.getIdPart()); assertEquals("1", id.getVersionIdPart()); - p = myPatientDao.read(id.toUnqualifiedVersionless()); + p = myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()); assertEquals("Patient/123abc", p.getId().toUnqualifiedVersionless().getValue()); assertEquals("Hello", p.getName().get(0).getFamily().get(0).getValue()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java index 19372453520..a21bcd601a0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java @@ -1,7 +1,8 @@ package ca.uhn.fhir.jpa.dao.dstu2; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.io.IOException; import java.util.Arrays; @@ -27,6 +28,7 @@ import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2ValidateTest.class); @@ -57,20 +59,20 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { private OperationOutcome doTestValidateResourceContainingProfileDeclaration(String methodName, EncodingEnum enc) throws IOException { Bundle vss = loadResourceFromClasspath(Bundle.class, "/org/hl7/fhir/instance/model/valueset/valuesets.xml"); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes")); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes"), new ServletRequestDetails()); StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/org/hl7/fhir/instance/model/profile/devicemetricobservation.profile.xml"); sd.setId(new IdDt()); sd.setUrl("http://example.com/foo/bar/" + methodName); - myStructureDefinitionDao.create(sd); + myStructureDefinitionDao.create(sd, new ServletRequestDetails()); Observation input = new Observation(); ResourceMetadataKeyEnum.PROFILES.put(input, Arrays.asList(new IdDt(sd.getUrl()))); @@ -87,7 +89,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { case JSON: encoded = myFhirCtx.newJsonParser().encodeResourceToString(input); try { - myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null); + myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails()); fail(); } catch (PreconditionFailedException e) { return (OperationOutcome) e.getOperationOutcome(); @@ -95,7 +97,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { case XML: encoded = myFhirCtx.newXmlParser().encodeResourceToString(input); try { - myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null); + myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null, new ServletRequestDetails()); fail(); } catch (PreconditionFailedException e) { return (OperationOutcome) e.getOperationOutcome(); @@ -120,7 +122,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { ValidationModeEnum mode = ValidationModeEnum.CREATE; String encoded = myFhirCtx.newJsonParser().encodeResourceToString(input); - MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null); + MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails()); String ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome()); ourLog.info(ooString); @@ -137,14 +139,14 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { pat.addName().addFamily(methodName); try { - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("ID must not be populated")); } pat.setId(""); - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails()); } @@ -155,12 +157,12 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { Patient pat = new Patient(); pat.setId("Patient/123"); pat.addName().addFamily(methodName); - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); pat.setId(""); try { - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("ID must be populated")); @@ -178,12 +180,12 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { Patient pat = new Patient(); pat.setId("Patient/123"); pat.addName().addFamily(methodName); - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); pat.setId(""); try { - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("ID must be populated")); @@ -198,16 +200,16 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat = new Patient(); pat.addName().addFamily(methodName); pat.getManagingOrganization().setReference(orgId); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); OperationOutcome outcome=null; try { - myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null); + myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails()); fail(); } catch (ResourceVersionConflictException e) { outcome= (OperationOutcome) e.getOperationOutcome(); @@ -219,9 +221,9 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { pat.setId(patId); pat.getManagingOrganization().setReference(""); - myPatientDao.update(pat); + myPatientDao.update(pat, new ServletRequestDetails()); - outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null).getOperationOutcome(); + outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails()).getOperationOutcome(); ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(ooString); assertThat(ooString, containsString("Ok to delete")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java index 194bc6f4865..657234d7d14 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java @@ -24,6 +24,7 @@ import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.UriDt; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { @@ -37,7 +38,7 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml"); upload.setId(""); - myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless(); + myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java index 1298de68908..64e3e3aa8de 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java @@ -17,6 +17,7 @@ import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { @@ -32,7 +33,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra"); patient.addName().addFamily("AAAS"); patient.addName().addFamily("CCC"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } Long id2; { @@ -41,13 +42,13 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA"); patient.addName().addFamily("AAAB"); patient.addName().addFamily("CCC"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } Long id3; { Organization org = new Organization(); org.setName("DDD"); - id3 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id3 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } SearchParameterMap map = new SearchParameterMap(); @@ -109,13 +110,13 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { Patient patient = new Patient(); patient.getText().setDiv("
AAAS

FOO

CCC
"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } Long id2; { Patient patient = new Patient(); patient.getText().setDiv("
AAAB

FOO

CCC
"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } SearchParameterMap map = new SearchParameterMap(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java index 9b4b0458b49..08216799925 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java @@ -65,6 +65,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { @@ -74,11 +75,11 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { public void testReindexing() { Patient p = new Patient(); p.addName().addFamily("family"); - final IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + final IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ValueSet vs = new ValueSet(); vs.setUrl("http://foo"); - myValueSetDao.create(vs); + myValueSetDao.create(vs, new ServletRequestDetails()); ResourceTable entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback() { @Override @@ -98,7 +99,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { }); assertEquals(null, entity.getIndexStatus()); - mySystemDao.performReindexingPass(null); + mySystemDao.performReindexingPass(null, new ServletRequestDetails()); entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback() { @Override @@ -109,7 +110,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals(Long.valueOf(1), entity.getIndexStatus()); // Just make sure this doesn't cause a choke - mySystemDao.performReindexingPass(100000); + mySystemDao.performReindexingPass(100000, new ServletRequestDetails()); // Try making the resource unparseable @@ -131,7 +132,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { } }); - mySystemDao.performReindexingPass(null); + mySystemDao.performReindexingPass(null, new ServletRequestDetails()); entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback() { @Override @@ -146,7 +147,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { @Test public void testSystemMetaOperation() { - MetaDt meta = mySystemDao.metaGetOperation(); + MetaDt meta = mySystemDao.metaGetOperation(new ServletRequestDetails()); List published = meta.getTag(); assertEquals(0, published.size()); @@ -168,7 +169,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { profiles.add(new IdDt("http://profile/1")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); @@ -186,10 +187,10 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { profiles.add(new IdDt("http://profile/2")); ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } - meta = mySystemDao.metaGetOperation(); + meta = mySystemDao.metaGetOperation(new ServletRequestDetails()); published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); @@ -211,11 +212,11 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals("http://profile/1", profiles.get(0).getValue()); assertEquals("http://profile/2", profiles.get(1).getValue()); - myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog"); - myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1"); - myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1"); + myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1", new ServletRequestDetails()); - meta = mySystemDao.metaGetOperation(); + meta = mySystemDao.metaGetOperation(new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -271,7 +272,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals("201 Created", respEntry.getStatus()); IdDt createdId = new IdDt(respEntry.getLocation()); assertEquals("Patient", createdId.getResourceType()); - myPatientDao.read(createdId); // shouldn't fail + myPatientDao.read(createdId, new ServletRequestDetails()); // shouldn't fail // Check GET respEntry = resp.getEntry().get(2).getResponse(); @@ -287,7 +288,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -315,7 +316,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1")); assertEquals("1", respEntry.getResponse().getEtag()); - o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement())); + o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement()), new ServletRequestDetails()); assertEquals(id.toVersionless(), o.getSubject().getReference()); assertEquals("1", o.getId().getVersionIdPart()); @@ -327,12 +328,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - id = myPatientDao.create(p).getId(); + id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); @@ -389,7 +390,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1")); assertEquals("1", respEntry.getResponse().getEtag()); - o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement())); + o = (Observation) myObservationDao.read(new IdDt(respEntry.getResponse().getLocationElement()), new ServletRequestDetails()); assertEquals(new IdDt(patientId).toUnqualifiedVersionless(), o.getSubject().getReference()); } @@ -552,13 +553,13 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id1 = myPatientDao.create(p1).getId(); + IIdType id1 = myPatientDao.create(p1, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id1); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue(methodName); p2.setId("Patient/" + methodName); - IIdType id2 = myPatientDao.update(p2).getId(); + IIdType id2 = myPatientDao.update(p2, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id2); Bundle request = new Bundle(); @@ -566,8 +567,8 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { request.addEntry().getRequest().setMethod(HTTPVerbEnum.DELETE).setUrl("Patient/" + id1.getIdPart()); request.addEntry().getRequest().setMethod(HTTPVerbEnum.DELETE).setUrl("Patient/" + id2.getIdPart()); - myPatientDao.read(id1.toVersionless()); - myPatientDao.read(id2.toVersionless()); + myPatientDao.read(id1.toVersionless(), new ServletRequestDetails()); + myPatientDao.read(id2.toVersionless(), new ServletRequestDetails()); Bundle resp = mySystemDao.transaction(myRequestDetails, request); @@ -576,14 +577,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals("204 No Content", resp.getEntry().get(1).getResponse().getStatus()); try { - myPatientDao.read(id1.toVersionless()); + myPatientDao.read(id1.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myPatientDao.read(id2.toVersionless()); + myPatientDao.read(id2.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -600,20 +601,20 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", pid); Observation o1 = new Observation(); o1.getSubject().setReference(pid); - IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.addIdentifier().setValue(methodName); o2.getSubject().setReference(pid); - IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); - myPatientDao.read(pid); - myObservationDao.read(oid1); + myPatientDao.read(pid, new ServletRequestDetails()); + myObservationDao.read(oid1, new ServletRequestDetails()); // The target is Patient, so try with it first in the bundle Bundle request = new Bundle(); @@ -628,21 +629,21 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus()); try { - myPatientDao.read(pid); + myPatientDao.read(pid, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid1); + myObservationDao.read(oid1, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid2); + myObservationDao.read(oid2, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -659,20 +660,20 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", pid); Observation o1 = new Observation(); o1.getSubject().setReference(pid); - IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.addIdentifier().setValue(methodName); o2.getSubject().setReference(pid); - IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); - myPatientDao.read(pid); - myObservationDao.read(oid1); + myPatientDao.read(pid, new ServletRequestDetails()); + myObservationDao.read(oid1, new ServletRequestDetails()); // The target is Patient, so try with it last in the bundle Bundle request = new Bundle(); @@ -687,21 +688,21 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus()); try { - myPatientDao.read(pid); + myPatientDao.read(pid, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid1); + myObservationDao.read(oid1, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid2); + myObservationDao.read(oid2, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -715,7 +716,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); @@ -728,20 +729,20 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", nextEntry.getResponse().getStatus()); try { - myPatientDao.read(id.toVersionless()); + myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // ok } try { - myPatientDao.read(new IdDt("Patient/" + methodName)); + myPatientDao.read(new IdDt("Patient/" + methodName), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // ok } - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(2, history.size()); assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IResource) history.getResources(0, 0).get(0))); @@ -758,12 +759,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - id = myPatientDao.create(p).getId(); + id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -807,7 +808,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); @@ -819,7 +820,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", res.getEntry().get(0).getResponse().getStatus()); try { - myPatientDao.read(id.toVersionless()); + myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // ok @@ -858,7 +859,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertThat(resp.getEntry().get(1).getResponse().getLocation(), startsWith("Patient/temp6789/_history/")); assertThat(resp.getEntry().get(2).getResponse().getLocation(), startsWith("Organization/GHH/_history/")); - Patient p = myPatientDao.read(new IdDt("Patient/a555-44-4444/_history/1")); + Patient p = myPatientDao.read(new IdDt("Patient/a555-44-4444/_history/1"), new ServletRequestDetails()); assertEquals("Patient/temp6789", p.getLink().get(0).getOther().getReference().getValue()); } @@ -974,14 +975,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType idv1 = myPatientDao.update(p).getId(); + IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got id: {}", idv1); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Family Name"); p.setId("Patient/" + methodName); - IIdType idv2 = myPatientDao.update(p).getId(); + IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Updated patient, got id: {}", idv2); Bundle request = new Bundle(); @@ -1044,14 +1045,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType idv1 = myPatientDao.update(p).getId(); + IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got id: {}", idv1); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Family Name"); p.setId("Patient/" + methodName); - IIdType idv2 = myPatientDao.update(p).getId(); + IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Updated patient, got id: {}", idv2); Bundle request = new Bundle(); @@ -1089,14 +1090,14 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType idv1 = myPatientDao.update(p).getId(); + IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got id: {}", idv1); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Family Name"); p.setId("Patient/" + methodName); - IIdType idv2 = myPatientDao.update(p).getId(); + IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Updated patient, got id: {}", idv2); Bundle request = new Bundle(); @@ -1152,7 +1153,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -1181,7 +1182,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertThat(nextEntry.getResponse().getLocation(), not(emptyString())); nextEntry = resp.getEntry().get(1); - o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation())); + o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation()), new ServletRequestDetails()); assertEquals(id.toVersionless(), o.getSubject().getReference()); } @@ -1193,12 +1194,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - id = myPatientDao.create(p).getId(); + id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -1227,7 +1228,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addName().addFamily("Hello"); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); @@ -1253,7 +1254,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertThat(patientId.getValue(), endsWith("/_history/1")); nextEntry = resp.getEntry().get(1); - o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation())); + o = myObservationDao.read(new IdDt(nextEntry.getResponse().getLocation()), new ServletRequestDetails()); assertEquals(patientId.toVersionless(), o.getSubject().getReference()); } @@ -1266,7 +1267,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -1294,7 +1295,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { nextEntry = resp.getEntry().get(1); assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", nextEntry.getResponse().getStatus()); - o = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation())); + o = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails()); assertEquals(id.toVersionless(), o.getSubject().getReference()); } @@ -1503,8 +1504,8 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation())); - o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation())); + o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails()); + o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails()); assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart())); assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart())); @@ -1546,8 +1547,8 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation())); - o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation())); + o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails()); + o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails()); assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart())); assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart())); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java index 823d69ba493..0e53554b349 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java @@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor; import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { @@ -48,7 +49,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { public void testJpaCreate() { Patient p = new Patient(); p.addName().addFamily("PATIENT"); - Long id = myPatientDao.create(p).getId().getIdPartAsLong(); + Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong(); ArgumentCaptor detailsCapt; ArgumentCaptor tableCapt; @@ -68,7 +69,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { */ p = new Patient(); p.addName().addFamily("PATIENT1"); - Long id2 = myPatientDao.create(p, "Patient?family=PATIENT").getId().getIdPartAsLong(); + Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", new ServletRequestDetails()).getId().getIdPartAsLong(); assertEquals(id, id2); detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); @@ -82,9 +83,9 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { public void testJpaDelete() { Patient p = new Patient(); p.addName().addFamily("PATIENT"); - Long id = myPatientDao.create(p).getId().getIdPartAsLong(); + Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong(); - myPatientDao.delete(new IdType("Patient", id)); + myPatientDao.delete(new IdType("Patient", id), new ServletRequestDetails()); ArgumentCaptor detailsCapt; ArgumentCaptor tableCapt; @@ -102,12 +103,12 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { public void testJpaUpdate() { Patient p = new Patient(); p.addName().addFamily("PATIENT"); - Long id = myPatientDao.create(p).getId().getIdPartAsLong(); + Long id = myPatientDao.create(p, new ServletRequestDetails()).getId().getIdPartAsLong(); p = new Patient(); p.setId(new IdType(id)); p.addName().addFamily("PATIENT1"); - Long id2 = myPatientDao.update(p).getId().getIdPartAsLong(); + Long id2 = myPatientDao.update(p, new ServletRequestDetails()).getId().getIdPartAsLong(); assertEquals(id, id2); ArgumentCaptor detailsCapt; @@ -126,7 +127,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { p = new Patient(); p.setId(new IdType(id)); p.addName().addFamily("PATIENT2"); - id2 = myPatientDao.update(p, "Patient?family=PATIENT1").getId().getIdPartAsLong(); + id2 = myPatientDao.update(p, "Patient?family=PATIENT1", new ServletRequestDetails()).getId().getIdPartAsLong(); assertEquals(id, id2); detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); @@ -141,7 +142,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { p = new Patient(); p.addName().addFamily("PATIENT3"); - id2 = myPatientDao.update(p, "Patient?family=ZZZ").getId().getIdPartAsLong(); + id2 = myPatientDao.update(p, "Patient?family=ZZZ", new ServletRequestDetails()).getId().getIdPartAsLong(); assertNotEquals(id, id2); detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java index 8df9c19757d..508da9b26b9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java @@ -17,10 +17,10 @@ import org.hl7.fhir.dstu3.model.Base64BinaryType; import org.hl7.fhir.dstu3.model.Device; import org.hl7.fhir.dstu3.model.Media; import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Quantity; import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Ignore; import org.junit.Test; @@ -32,6 +32,7 @@ import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { @@ -45,13 +46,13 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs1.setStatus(ObservationStatus.FINAL); obs1.setValue(new Quantity(123)); obs1.setComments("obs1"); - IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getCode().setText("Diastolic Blood Pressure"); obs2.setStatus(ObservationStatus.FINAL); obs2.setValue(new Quantity(81)); - IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map; @@ -77,13 +78,13 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs1.getCode().setText("AAAAA"); obs1.setValue(new StringType("Systolic Blood Pressure")); obs1.setStatus(ObservationStatus.FINAL); - IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs1.getCode().setText("AAAAA"); obs1.setValue(new StringType("Diastolic Blood Pressure")); obs2.setStatus(ObservationStatus.FINAL); - IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map; @@ -98,7 +99,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { public void testSuggestIgnoresBase64Content() { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Media med = new Media(); med.getSubject().setReferenceElement(ptId); @@ -106,7 +107,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { med.getContent().setContentType("LCws"); med.getContent().setDataElement(new Base64BinaryType(new byte[] {44,44,44,44,44,44,44,44})); med.getContent().setTitle("bbbb syst"); - myMediaDao.create(med); + myMediaDao.create(med, new ServletRequestDetails()); ourLog.info(myFhirCtx.newJsonParser().encodeResourceToString(med)); List output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "press"); @@ -138,35 +139,35 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { public void testSuggest() { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReferenceElement(ptId); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); obs = new Observation(); obs.getSubject().setReferenceElement(ptId); obs.getCode().setText("MNBVCXZ"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); obs = new Observation(); obs.getSubject().setReferenceElement(ptId); obs.getCode().setText("ZXC HELLO"); obs.addComponent().getCode().setText("HHHHHHHHHH"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); /* * These shouldn't match since they're for another patient */ patient = new Patient(); patient.addName().addFamily("testSuggest2"); - IIdType ptId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReferenceElement(ptId2); obs2.getCode().setText("ZXCVBNMZZ"); - myObservationDao.create(obs2); + myObservationDao.create(obs2, new ServletRequestDetails()); List output = mySearchDao.suggestKeywords("Patient/" + ptId.getIdPart() + "/$everything", "_content", "ZXCVBNM"); ourLog.info("Found: " + output); @@ -211,7 +212,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { patient = new Patient(); patient.getText().setDivAsString("
DIVAAA
"); patient.addName().addGiven("NAMEAAA"); - IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -229,7 +230,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { patient.setId(pId1); patient.getText().setDivAsString("
DIVBBB
"); patient.addName().addGiven("NAMEBBB"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -253,19 +254,19 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { public void testEverythingInstanceWithContentFilter() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); - IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); + IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); - myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); + myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.getText().setDivAsString("
OBSTEXT1
"); @@ -273,19 +274,19 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs1.getCode().addCoding().setCode("CODE1"); obs1.setValue(new StringType("obsvalue1")); obs1.getDevice().setReferenceElement(devId1); - IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReferenceElement(ptId1); obs2.getCode().addCoding().setCode("CODE2"); obs2.setValue(new StringType("obsvalue2")); - IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs3 = new Observation(); obs3.getSubject().setReferenceElement(ptId2); obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringType("obsvalue3")); - IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); + IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); HttpServletRequest request; List actual; @@ -296,16 +297,16 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1))); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obstext1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, param, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1))); request = mock(HttpServletRequest.class); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, null, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId2, devId1))); /* @@ -316,12 +317,12 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs4.getSubject().setReferenceElement(ptId1); obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringType("obsvalue1")); - IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless(); + IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId4, devId1))); /* @@ -333,11 +334,11 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs1.getSubject().setReferenceElement(ptId1); obs1.getCode().addCoding().setCode("CODE2"); obs1.setValue(new StringType("obsvalue2")); - myObservationDao.update(obs1); + myObservationDao.update(obs1, new ServletRequestDetails()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientInstanceEverything(request, ptId1, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId4))); } @@ -346,38 +347,38 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { public void testEverythingTypeWithContentFilter() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); - IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); + IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); - IIdType devId2 = myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); + IIdType devId2 = myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.getSubject().setReferenceElement(ptId1); obs1.getCode().addCoding().setCode("CODE1"); obs1.setValue(new StringType("obsvalue1")); obs1.getDevice().setReferenceElement(devId1); - IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReferenceElement(ptId1); obs2.getCode().addCoding().setCode("CODE2"); obs2.setValue(new StringType("obsvalue2")); - IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs3 = new Observation(); obs3.getSubject().setReferenceElement(ptId2); obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringType("obsvalue3")); - IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); + IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); HttpServletRequest request; List actual; @@ -388,11 +389,11 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, devId1))); request = mock(HttpServletRequest.class); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, null, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId2, devId1, ptId2, obsId3))); /* @@ -403,12 +404,12 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs4.getSubject().setReferenceElement(ptId1); obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringType("obsvalue1")); - IIdType obsId4 = myObservationDao.create(obs4).getId().toUnqualifiedVersionless(); + IIdType obsId4 = myObservationDao.create(obs4, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId1, obsId4, devId1))); /* @@ -420,11 +421,11 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs1.getSubject().setReferenceElement(ptId1); obs1.getCode().addCoding().setCode("CODE2"); obs1.setValue(new StringType("obsvalue2")); - myObservationDao.update(obs1); + myObservationDao.update(obs1, new ServletRequestDetails()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); - actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null)); + actual = toUnqualifiedVersionlessIdValues(myPatientDao.patientTypeEverything(request, null, null, null, param, null, new ServletRequestDetails())); assertThat(actual, containsInAnyOrder(toValues(ptId1, obsId4))); } @@ -442,7 +443,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { patient = new Patient(); patient.getText().setDivAsString("
DIVAAA
"); patient.addName().addGiven("NAMEAAA"); - IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -460,7 +461,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { patient.setId(pId1); patient.getText().setDivAsString("
DIVBBB
"); patient.addName().addGiven("NAMEBBB"); - myPatientDao.update(patient, null, false); + myPatientDao.update(patient, null, false, new ServletRequestDetails()); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -469,7 +470,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), not(contains(toValues(pId1)))); - myPatientDao.update(patient, null, true); + myPatientDao.update(patient, null, true, new ServletRequestDetails()); map = new SearchParameterMap(); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); @@ -497,18 +498,18 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addName().addGiven(methodName); patient.addAddress().addLine("My fulltext address"); - pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + pId1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Observation obs = new Observation(); obs.getSubject().setReferenceElement(pId1); obs.setValue(new StringType("This is the FULLtext of the observation")); - IIdType oId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType oId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId1); obs.setValue(new StringType("Another fullText")); - IIdType oId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType oId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List patients; SearchParameterMap params; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index 2669598952f..e56a22b1a9c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.dstu3.model.BaseResource; import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.ConceptMap; +import org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem; import org.hl7.fhir.dstu3.model.DateTimeType; import org.hl7.fhir.dstu3.model.DateType; import org.hl7.fhir.dstu3.model.Device; @@ -46,12 +47,11 @@ import org.hl7.fhir.dstu3.model.Quantity; import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.Subscription; +import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; +import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.dstu3.model.Substance; import org.hl7.fhir.dstu3.model.TemporalPrecisionEnum; import org.hl7.fhir.dstu3.model.ValueSet; -import org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem; -import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; -import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Ignore; @@ -90,6 +90,7 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { @@ -101,7 +102,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { subs.setStatus(SubscriptionStatus.ACTIVE); subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?"); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map = new SearchParameterMap(); map.add(Subscription.SP_TYPE, new TokenParam(null, SubscriptionChannelType.WEBSOCKET.toCode())); @@ -115,33 +116,33 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Medication med = new Medication(); med.getCode().setText(methodName); - IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); + IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat = new Patient(); pat.addAddress().addLine(methodName); pat.getManagingOrganization().setReferenceElement(orgId); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat2 = new Patient(); pat2.addAddress().addLine(methodName); pat2.getManagingOrganization().setReferenceElement(orgId); - IIdType patId2 = myPatientDao.create(pat2).getId().toUnqualifiedVersionless(); + IIdType patId2 = myPatientDao.create(pat2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); MedicationOrder mo = new MedicationOrder(); mo.getPatient().setReferenceElement(patId); mo.setMedication(new Reference(medId)); - IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); + IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); HttpServletRequest request = mock(HttpServletRequest.class); - IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null); + IBundleProvider resp = myPatientDao.patientTypeEverything(request, null, null, null, null, null, new ServletRequestDetails()); assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId, patId2)); request = mock(HttpServletRequest.class); - resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null); + resp = myPatientDao.patientInstanceEverything(request, patId, null, null, null, null, null, new ServletRequestDetails()); assertThat(toUnqualifiedVersionlessIds(resp), containsInAnyOrder(orgId, medId, patId, moId)); } @@ -155,7 +156,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z")); order.addItem().addEvent().setDateTimeElement(new DateTimeType("2011-12-12T11:12:12Z")); - IIdType id = myDiagnosticOrderDao.create(order).getId().toUnqualifiedVersionless(); + IIdType id = myDiagnosticOrderDao.create(order, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual = toUnqualifiedVersionlessIds(myDiagnosticOrderDao.search(DiagnosticOrder.SP_ITEM_DATE, new DateParam("2011-12-12T11:12:12Z"))); assertThat(actual, contains(id)); @@ -176,7 +177,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { res.addVaccinationProtocol().setDoseSequence(2); res.addVaccinationProtocol().setDoseSequence(2); - IIdType id = myImmunizationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myImmunizationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual = toUnqualifiedVersionlessIds(myImmunizationDao.search(Immunization.SP_DOSE_SEQUENCE, new NumberParam("1"))); assertThat(actual, contains(id)); @@ -195,7 +196,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232); res.addInstance().getQuantity().setSystem("http://foo2").setCode("UNIT2").setValue(1232); - IIdType id = mySubstanceDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = mySubstanceDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamQuantity.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -211,11 +212,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Practitioner pract =new Practitioner(); pract.setId("Practitioner/somepract"); pract.getName().addFamily("SOME PRACT"); - myPractitionerDao.update(pract); + myPractitionerDao.update(pract, new ServletRequestDetails()); Practitioner pract2 =new Practitioner(); pract2.setId("Practitioner/somepract2"); pract2.getName().addFamily("SOME PRACT2"); - myPractitionerDao.update(pract2); + myPractitionerDao.update(pract2, new ServletRequestDetails()); DiagnosticOrder res = new DiagnosticOrder(); res.addEvent().setActor(new Reference("Practitioner/somepract")); @@ -223,7 +224,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { res.addEvent().setActor(new Reference("Practitioner/somepract2")); res.addEvent().setActor(new Reference("Practitioner/somepract2")); - IIdType id = myDiagnosticOrderDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myDiagnosticOrderDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceLink.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -244,7 +245,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { p.addAddress().addLine("456 Fake Street"); p.addAddress().addLine("456 Fake Street"); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamString.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -263,7 +264,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { res.addIdentifier().setSystem("http://foo2").setValue("1234"); res.addIdentifier().setSystem("http://foo2").setValue("1234"); - IIdType id = myPatientDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamToken.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -282,7 +283,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { res.addElement().addTarget().addDependsOn().setElement("http://bar"); res.addElement().addTarget().addDependsOn().setElement("http://bar"); - IIdType id = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Class type = ResourceIndexedSearchParamUri.class; List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList(); @@ -299,13 +300,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester").addGiven("Joe"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -319,13 +320,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } IIdType id2; { Organization patient = new Organization(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myOrganizationDao.create(patient).getId(); + id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId(); } Map params = new HashMap(); @@ -346,13 +347,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } SearchParameterMap params; @@ -394,14 +395,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } long betweenTime = System.currentTimeMillis(); IIdType id2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } SearchParameterMap params = new SearchParameterMap(); @@ -431,13 +432,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Organization patient = new Organization(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myOrganizationDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myOrganizationDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } SearchParameterMap params = new SearchParameterMap(); @@ -451,12 +452,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01"); o1.setValue(new StringType("testSearchCompositeParamS01")); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamN01"); o2.setValue(new StringType("testSearchCompositeParamS02")); - IIdType id2 = myObservationDao.create(o2).getId(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId(); { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01"); @@ -481,12 +482,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01"); o1.setValue(new Period().setStartElement(new DateTimeType("2001-01-01T11:11:11"))); - IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01"); o2.setValue(new Period().setStartElement(new DateTimeType("2001-01-01T12:12:12"))); - IIdType id2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); @@ -521,7 +522,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.setLanguageElement(new CodeType("TEST")); patient.addName().addFamily("TEST"); patient.addIdentifier().setSystem("TEST").setValue("TEST"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -537,7 +538,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { params.put(Patient.SP_NAME, new StringParam("TEST")); assertEquals(1, toList(myPatientDao.search(params)).size()); - myPatientDao.delete(new IdType("Patient/TEST")); + myPatientDao.delete(new IdType("Patient/TEST"), new ServletRequestDetails()); params = new HashMap(); params.put("_id", new StringParam("TEST")); @@ -573,7 +574,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.getLanguageElement().setValue("en_CA"); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } IIdType id2; { @@ -581,7 +582,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.getLanguageElement().setValue("en_US"); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("testSearchLanguageParam").addGiven("John"); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Map params = new HashMap(); @@ -613,7 +614,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.getLanguageElement().setValue("en_CA"); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("testSearchLanguageParam").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Date betweenTime = new Date(); @@ -624,7 +625,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.getLanguageElement().setValue("en_US"); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("testSearchLanguageParam").addGiven("John"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { SearchParameterMap params = new SearchParameterMap(); @@ -708,14 +709,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily(methodName).addGiven("Joe"); - id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id1b; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily(methodName + "XXXX").addGiven("Joe"); - id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Thread.sleep(1100); @@ -727,7 +728,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily(methodName).addGiven("John"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -772,7 +773,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id0 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id0 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } int sleep = 100; @@ -785,18 +786,18 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1a = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1a = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id1b; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1b = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1b = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } - ourLog.info("Res 1: {}", myPatientDao.read(id0).getMeta().getLastUpdatedElement().getValueAsString()); - ourLog.info("Res 2: {}", myPatientDao.read(id1a).getMeta().getLastUpdatedElement().getValueAsString()); - ourLog.info("Res 3: {}", myPatientDao.read(id1b).getMeta().getLastUpdatedElement().getValueAsString()); + ourLog.info("Res 1: {}", myPatientDao.read(id0, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValueAsString()); + ourLog.info("Res 2: {}", myPatientDao.read(id1a, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValueAsString()); + ourLog.info("Res 3: {}", myPatientDao.read(id1b, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValueAsString()); Thread.sleep(sleep); @@ -824,7 +825,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a, id1b)); map = new SearchParameterMap(); - map.setLastUpdated(new DateRangeParam(new DateParam(QuantityCompararatorEnum.GREATERTHAN, startDateTime.getValue()), new DateParam(QuantityCompararatorEnum.LESSTHAN, myPatientDao.read(id1b).getMeta().getLastUpdatedElement().getValue()))); + map.setLastUpdated(new DateRangeParam(new DateParam(QuantityCompararatorEnum.GREATERTHAN, startDateTime.getValue()), new DateParam(QuantityCompararatorEnum.LESSTHAN, myPatientDao.read(id1b, new ServletRequestDetails()).getMeta().getLastUpdatedElement().getValue()))); ourLog.info("Searching: {}", map.getLastUpdated()); assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a)); } @@ -835,13 +836,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("testSearchNameParam01Fam").addGiven("testSearchNameParam01Giv"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("testSearchNameParam02Fam").addGiven("testSearchNameParam02Giv"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -884,7 +885,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Location loc = new Location(); loc.getPosition().setLatitude(43.7); loc.getPosition().setLatitude(79.4); - myLocationDao.create(loc); + myLocationDao.create(loc, new ServletRequestDetails()); } } @@ -894,12 +895,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Encounter e1 = new Encounter(); e1.addIdentifier().setSystem("foo").setValue("testSearchNumberParam01"); e1.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60); - IIdType id1 = myEncounterDao.create(e1).getId(); + IIdType id1 = myEncounterDao.create(e1, new ServletRequestDetails()).getId(); Encounter e2 = new Encounter(); e2.addIdentifier().setSystem("foo").setValue("testSearchNumberParam02"); e2.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(2.0); - IIdType id2 = myEncounterDao.create(e2).getId(); + IIdType id2 = myEncounterDao.create(e2, new ServletRequestDetails()).getId(); { IBundleProvider found = myEncounterDao.search(Encounter.SP_LENGTH, new NumberParam(">2")); assertEquals(2, found.size()); @@ -924,7 +925,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.addName().addFamily(name); - id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Map params = new HashMap(); @@ -935,7 +936,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem(name).setValue(name); patient.setId(id); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); params = new HashMap(); params.put(Patient.SP_FAMILY, new StringParam(name)); @@ -952,14 +953,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Practitioner patient = new Practitioner(); patient.getName().addFamily(methodName); patient.addTelecom().setSystem(ContactPointSystem.PHONE).setValue("123"); - id1 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Practitioner patient = new Practitioner(); patient.getName().addFamily(methodName); patient.addTelecom().setSystem(ContactPointSystem.EMAIL).setValue("abc"); - id2 = myPractitionerDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPractitionerDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Map params; @@ -998,27 +999,27 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX"); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain01"); - IIdType patientId01 = myPatientDao.create(patient).getId(); + IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Patient patient02 = new Patient(); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChainXX"); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithChain02"); - IIdType patientId02 = myPatientDao.create(patient02).getId(); + IIdType patientId02 = myPatientDao.create(patient02, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeType(new Date())); obs01.setSubject(new Reference(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(patientId02)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); // Create another type, that shouldn't be returned DiagnosticReport dr01 = new DiagnosticReport(); dr01.setSubject(new Reference(patientId01)); - IIdType drId01 = myDiagnosticReportDao.create(dr01).getId(); + IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 }); @@ -1052,19 +1053,19 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId01 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId01 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Location locParent = new Location(); locParent.setManagingOrganization(new Reference(orgId01)); - IIdType locParentId = myLocationDao.create(locParent).getId().toUnqualifiedVersionless(); + IIdType locParentId = myLocationDao.create(locParent, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Location locChild = new Location(); locChild.setPartOf(new Reference(locParentId)); - IIdType locChildId = myLocationDao.create(locChild).getId().toUnqualifiedVersionless(); + IIdType locChildId = myLocationDao.create(locChild, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Location locGrandchild = new Location(); locGrandchild.setPartOf(new Reference(locChildId)); - IIdType locGrandchildId = myLocationDao.create(locGrandchild).getId().toUnqualifiedVersionless(); + IIdType locGrandchildId = myLocationDao.create(locGrandchild, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider found; ReferenceParam param; @@ -1097,21 +1098,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01"); patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypesXX"); - IIdType patientId01 = myPatientDao.create(patient).getId(); + IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Location loc01 = new Location(); loc01.getNameElement().setValue("testSearchResourceLinkWithChainWithMultipleTypes01"); - IIdType locId01 = myLocationDao.create(loc01).getId(); + IIdType locId01 = myLocationDao.create(loc01, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeType(new Date())); obs01.setSubject(new Reference(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(locId01)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] L1[{}] Obs1[{}] Obs2[{}]", new Object[] { patientId01, locId01, obsId01, obsId02 }); @@ -1138,28 +1139,28 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.setId("testSearchResourceLinkWithTextLogicalId01"); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX"); patient.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId01"); - IIdType patientId01 = myPatientDao.update(patient).getId(); + IIdType patientId01 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); Patient patient02 = new Patient(); patient02.setId("testSearchResourceLinkWithTextLogicalId02"); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalIdXX"); patient02.addIdentifier().setSystem("urn:system").setValue("testSearchResourceLinkWithTextLogicalId02"); - IIdType patientId02 = myPatientDao.update(patient02).getId(); + IIdType patientId02 = myPatientDao.update(patient02, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeType(new Date())); obs01.setSubject(new Reference(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(patientId02)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); // Create another type, that shouldn't be returned DiagnosticReport dr01 = new DiagnosticReport(); dr01.setSubject(new Reference(patientId01)); - IIdType drId01 = myDiagnosticReportDao.create(dr01).getId(); + IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 }); @@ -1190,13 +1191,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testSearchStringParam").addGiven("Joe"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -1221,12 +1222,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily(value); - longId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + longId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); - shortId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + shortId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Map params = new HashMap(); @@ -1245,13 +1246,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } Map params = new HashMap(); @@ -1273,12 +1274,12 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001"); patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1"); patient.addCommunication().getLanguage().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem").setDisplay("testSearchTokenParamDisplay"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam002"); patient.addName().addFamily("Tester").addGiven("testSearchTokenParam2"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); { SearchParameterMap map = new SearchParameterMap(); @@ -1381,7 +1382,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Quantity q = new Quantity().setSystem("urn:bar:" + methodName).setCode(methodName + "units").setValue(100); o.setValue(q); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); param = new QuantityParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, null); found = myObservationDao.searchForIds("value-quantity", param); @@ -1420,25 +1421,25 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentOrgId = myOrganizationDao.create(org).getId(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId(); } { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new Reference(parentOrgId)); - IIdType orgId = myOrganizationDao.create(org).getId(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId(); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReferenceElement(orgId); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_" + methodName + "_P2").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { @@ -1527,21 +1528,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new Reference(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new Reference(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1549,7 +1550,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReferenceElement(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1569,21 +1570,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new Reference(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new Reference(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1591,7 +1592,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReferenceElement(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1611,21 +1612,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new Reference(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new Reference(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1633,7 +1634,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReferenceElement(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1652,21 +1653,21 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentParentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentParentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType parentOrgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); org.setPartOf(new Reference(parentParentOrgId)); - parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + parentOrgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType orgId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new Reference(parentOrgId)); - orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType patientId; { @@ -1674,7 +1675,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReferenceElement(orgId); - patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + patientId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -1695,20 +1696,20 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Organization org = new Organization(); org.setId("testSearchWithIncludesThatHaveTextIdid1"); org.getNameElement().setValue("testSearchWithIncludesThatHaveTextId_O1"); - IIdType orgId = myOrganizationDao.update(org).getId(); + IIdType orgId = myOrganizationDao.update(org, new ServletRequestDetails()).getId(); assertThat(orgId.getValue(), endsWith("Organization/testSearchWithIncludesThatHaveTextIdid1/_history/1")); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe"); patient.getManagingOrganization().setReferenceElement(orgId); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P2").addGiven("John"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } SearchParameterMap params = new SearchParameterMap(); @@ -1729,13 +1730,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { @Test public void testSearchWithMissingDate() { - IIdType orgId = myOrganizationDao.create(new Organization()).getId(); + IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId(); IIdType notMissing; IIdType missing; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); @@ -1743,7 +1744,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); patient.setBirthDateElement(new DateType("2011-01-01")); patient.getManagingOrganization().setReferenceElement(orgId); - notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Date Param { @@ -1773,13 +1774,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("002"); obs.setValue(new Quantity(123)); - notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Quantity Param { @@ -1804,13 +1805,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { @Test public void testSearchWithMissingReference() { - IIdType orgId = myOrganizationDao.create(new Organization()).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IIdType notMissing; IIdType missing; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); @@ -1818,7 +1819,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); patient.setBirthDateElement(new DateType("2011-01-01")); patient.getManagingOrganization().setReferenceElement(orgId); - notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Reference Param { @@ -1844,13 +1845,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { @Test public void testSearchWithMissingString() { - IIdType orgId = myOrganizationDao.create(new Organization()).getId(); + IIdType orgId = myOrganizationDao.create(new Organization(), new ServletRequestDetails()).getId(); IIdType notMissing; IIdType missing; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + missing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient patient = new Patient(); @@ -1858,7 +1859,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { patient.addName().addFamily("Tester_testSearchStringParam").addGiven("John"); patient.setBirthDateElement(new DateType("2011-01-01")); patient.getManagingOrganization().setReferenceElement(orgId); - notMissing = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + notMissing = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // String Param { @@ -1885,13 +1886,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { public void testSearchWithNoResults() { Device dev = new Device(); dev.addIdentifier().setSystem("Foo"); - myDeviceDao.create(dev); + myDeviceDao.create(dev, new ServletRequestDetails()); IBundleProvider value = myDeviceDao.search(new SearchParameterMap()); ourLog.info("Initial size: " + value.size()); for (IBaseResource next : value.getResources(0, value.size())) { ourLog.info("Deleting: {}", next.getIdElement()); - myDeviceDao.delete((IIdType) next.getIdElement()); + myDeviceDao.delete((IIdType) next.getIdElement(), new ServletRequestDetails()); } value = myDeviceDao.search(new SearchParameterMap()); @@ -1915,14 +1916,14 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Organization org = new Organization(); org.getNameElement().setValue("FOO"); org.getMeta().addSecurity("urn:taglist", methodName + "1a", null); - tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType tag2id; { Organization org = new Organization(); org.getNameElement().setValue("FOO"); org.getMeta().addProfile("http://" + methodName); - tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { SearchParameterMap params = new SearchParameterMap(); @@ -1948,7 +1949,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { org.getNameElement().setValue("FOO"); org.getMeta().addTag("urn:taglist", methodName + "1a", null); org.getMeta().addTag("urn:taglist", methodName + "1b", null); - tag1id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag1id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } Date betweenDate = new Date(); @@ -1959,7 +1960,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { org.getNameElement().setValue("FOO"); org.getMeta().addTag("urn:taglist", methodName + "2a",null); org.getMeta().addTag("urn:taglist", methodName + "2b",null); - tag2id = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + tag2id = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { @@ -2029,13 +2030,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("001"); - missing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + missing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:system").setValue("002"); obs.getCode().addCoding().setSystem("urn:system").setCode("002"); - notMissing = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + notMissing = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Token Param { @@ -2062,15 +2063,15 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { public void testSearchWithUriParamAbove() throws Exception { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); - myValueSetDao.create(vs1).getId().toUnqualifiedVersionless(); + myValueSetDao.create(vs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ValueSet vs2 = new ValueSet(); vs2.setUrl("http://hl7.org/foo/bar"); - IIdType id2 = myValueSetDao.create(vs2).getId().toUnqualifiedVersionless(); + IIdType id2 = myValueSetDao.create(vs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ValueSet vs3 = new ValueSet(); vs3.setUrl("http://hl7.org/foo/bar/baz"); - IIdType id3 = myValueSetDao.create(vs3).getId().toUnqualifiedVersionless(); + IIdType id3 = myValueSetDao.create(vs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider result; result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/foo/bar/baz/boz").setQualifier(UriParamQualifierEnum.ABOVE)); @@ -2094,11 +2095,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Class type = ValueSet.class; String resourceName = "/valueset-dstu2.json"; ValueSet vs = loadResourceFromClasspath(type, resourceName); - IIdType id1 = myValueSetDao.update(vs).getId().toUnqualifiedVersionless(); + IIdType id1 = myValueSetDao.update(vs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ValueSet vs2 = new ValueSet(); vs2.setUrl("http://hl7.org/foo/bar"); - IIdType id2 = myValueSetDao.create(vs2).getId().toUnqualifiedVersionless(); + IIdType id2 = myValueSetDao.create(vs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider result; result = myValueSetDao.search(ValueSet.SP_URL, new UriParam("http://hl7.org/fhir/ValueSet/basic-resource-type")); @@ -2116,11 +2117,11 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Class type = ValueSet.class; String resourceName = "/valueset-dstu2.json"; ValueSet vs = loadResourceFromClasspath(type, resourceName); - IIdType id1 = myValueSetDao.update(vs).getId().toUnqualifiedVersionless(); + IIdType id1 = myValueSetDao.update(vs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ValueSet vs2 = new ValueSet(); vs2.setUrl("http://hl7.org/foo/bar"); - IIdType id2 = myValueSetDao.create(vs2).getId().toUnqualifiedVersionless(); + IIdType id2 = myValueSetDao.create(vs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider result; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java index af8627d6506..49ba75d0951 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java @@ -20,9 +20,9 @@ import java.util.List; import javax.persistence.TypedQuery; import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Subscription; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -38,6 +38,7 @@ import ca.uhn.fhir.jpa.entity.SubscriptionTable; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { @@ -64,16 +65,16 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setStatus(SubscriptionStatus.REQUESTED); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); mySubscriptionDao.purgeInactiveSubscriptions(); - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); Thread.sleep(1500); myDaoConfig.setSchedulingDisabled(false); mySubscriptionDao.purgeInactiveSubscriptions(); try { - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -95,9 +96,9 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setStatus(SubscriptionStatus.REQUESTED); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); mySubscriptionDao.purgeInactiveSubscriptions(); - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); mySubscriptionDao.getUndeliveredResourcesAndPurge(mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(id)); @@ -106,7 +107,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { myDaoConfig.setSchedulingDisabled(false); mySubscriptionDao.purgeInactiveSubscriptions(); try { - mySubscriptionDao.read(id); + mySubscriptionDao.read(id, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -120,7 +121,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setStatus(SubscriptionStatus.REQUESTED); - IIdType id = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType id = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); TypedQuery q = myEntityManager.createQuery("SELECT t from SubscriptionTable t WHERE t.mySubscriptionResource.myId = :id", SubscriptionTable.class); q.setParameter("id", id.getIdPartAsLong()); @@ -130,15 +131,15 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { assertNotNull(table.getNextCheck()); assertEquals(table.getNextCheck(), table.getSubscriptionResource().getPublished().getValue()); assertEquals(SubscriptionStatus.REQUESTED.toCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus()); - assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValue()); + assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValue()); subs.setStatus(SubscriptionStatus.ACTIVE); - mySubscriptionDao.update(subs); + mySubscriptionDao.update(subs, new ServletRequestDetails()); assertEquals(SubscriptionStatus.ACTIVE.toCode(), myEntityManager.find(SubscriptionTable.class, table.getId()).getStatus()); - assertEquals(SubscriptionStatus.ACTIVE, mySubscriptionDao.read(id).getStatusElement().getValue()); + assertEquals(SubscriptionStatus.ACTIVE, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValue()); - mySubscriptionDao.delete(id); + mySubscriptionDao.delete(id, new ServletRequestDetails()); assertNull(myEntityManager.find(SubscriptionTable.class, table.getId())); @@ -151,10 +152,10 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setId(id); subs.setStatus(SubscriptionStatus.REQUESTED); - mySubscriptionDao.update(subs); + mySubscriptionDao.update(subs, new ServletRequestDetails()); assertEquals(SubscriptionStatus.REQUESTED.toCode(), myEntityManager.createQuery("SELECT t FROM SubscriptionTable t WHERE t.myResId = " + id.getIdPart(), SubscriptionTable.class).getSingleResult().getStatus()); - assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id).getStatusElement().getValue()); + assertEquals(SubscriptionStatus.REQUESTED, mySubscriptionDao.read(id, new ServletRequestDetails()).getStatusElement().getValue()); } @Test @@ -163,7 +164,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.setStatus(SubscriptionStatus.REQUESTED); subs.setCriteria("Observation"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\"")); @@ -173,7 +174,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.setStatus(SubscriptionStatus.REQUESTED); subs.setCriteria("http://foo.com/Observation?AAA=BBB"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.criteria must be in the form \"{Resource Type}?[params]\"")); @@ -183,7 +184,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.setStatus(SubscriptionStatus.REQUESTED); subs.setCriteria("ObservationZZZZ?a=b"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.criteria contains invalid/unsupported resource type: ObservationZZZZ")); @@ -193,7 +194,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.setStatus(SubscriptionStatus.REQUESTED); subs.setCriteria("Observation?identifier=123"); try { - mySubscriptionDao.create(subs); + mySubscriptionDao.create(subs, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.channel.type must be populated on this server")); @@ -203,7 +204,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.setStatus(SubscriptionStatus.REQUESTED); subs.setCriteria("Observation?identifier=123"); subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); - assertTrue(mySubscriptionDao.create(subs).getId().hasIdPart()); + assertTrue(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().hasIdPart()); } @@ -214,7 +215,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { String methodName = "testDeleteSubscriptionWithFlaggedResources"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs; @@ -226,7 +227,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatus.ACTIVE); - IIdType subsId = mySubscriptionDao.create(subs).getId().toUnqualifiedVersionless(); + IIdType subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Long subsPid = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(subsId); assertNull(mySubscriptionTableDao.findOne(subsPid).getLastClientPoll()); @@ -239,12 +240,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { Observation obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -258,7 +259,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { * Delete the subscription */ - mySubscriptionDao.delete(subsId); + mySubscriptionDao.delete(subsId, new ServletRequestDetails()); assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L))); assertThat(mySubscriptionTableDao.count(), not(greaterThan(0L))); @@ -266,14 +267,14 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { /* * Delete a second time just to make sure that works */ - mySubscriptionDao.delete(subsId); + mySubscriptionDao.delete(subsId, new ServletRequestDetails()); /* * Re-create the subscription */ subs.setId(subsId); - mySubscriptionDao.update(subs).getId(); + mySubscriptionDao.update(subs, new ServletRequestDetails()).getId(); assertThat(mySubscriptionFlaggedResourceDataDao.count(), not(greaterThan(0L))); assertThat(mySubscriptionTableDao.count(), (greaterThan(0L))); @@ -285,7 +286,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -302,12 +303,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { String methodName = "testSubscriptionResourcesAppear"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs; @@ -319,13 +320,13 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatus.ACTIVE); - Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId()); + Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId()); subs = new Subscription(); subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatus.ACTIVE); - Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId()); + Long subsId2 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId()); assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll()); @@ -335,12 +336,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -381,7 +382,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { */ mySystemDao.markAllResourcesForReindexing(); - mySystemDao.performReindexingPass(100); + mySystemDao.performReindexingPass(100, new ServletRequestDetails()); assertEquals(0, mySubscriptionDao.pollForNewUndeliveredResources()); @@ -394,7 +395,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { ourLog.info("Updating observation"); Observation nextObs = (Observation) next; nextObs.addPerformer().setDisplay("Some display"); - myObservationDao.update(nextObs); + myObservationDao.update(nextObs, new ServletRequestDetails()); } assertEquals(6, mySubscriptionDao.pollForNewUndeliveredResources()); @@ -410,12 +411,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { String methodName = "testSubscriptionResourcesAppear2"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType oId = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType oId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs; @@ -427,7 +428,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatus.ACTIVE); - Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs).getId()); + Long subsId1 = mySubscriptionDao.getSubscriptionTablePidForSubscriptionResource(mySubscriptionDao.create(subs, new ServletRequestDetails()).getId()); assertNull(mySubscriptionTableDao.findOne(subsId1).getLastClientPoll()); @@ -435,7 +436,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { ourLog.info("pId: {} - oId: {}", pId, oId); - myObservationDao.update(myObservationDao.read(oId)); + myObservationDao.update(myObservationDao.read(oId, new ServletRequestDetails()), new ServletRequestDetails()); assertEquals(1, mySubscriptionDao.pollForNewUndeliveredResources()); ourLog.info("Between passes"); @@ -447,12 +448,12 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -476,7 +477,7 @@ public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); mySubscriptionDao.pollForNewUndeliveredResources(); assertEquals(4, mySubscriptionFlaggedResourceDataDao.count()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java index 8a257b59e9b..dae0984d07c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java @@ -36,6 +36,7 @@ import org.hamcrest.Matchers; import org.hamcrest.core.StringContains; import org.hl7.fhir.dstu3.model.BaseResource; import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; @@ -45,24 +46,23 @@ import org.hl7.fhir.dstu3.model.DateType; import org.hl7.fhir.dstu3.model.Device; import org.hl7.fhir.dstu3.model.DiagnosticReport; import org.hl7.fhir.dstu3.model.Encounter; +import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Meta; import org.hl7.fhir.dstu3.model.NamingSystem; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.OperationOutcome; +import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity; +import org.hl7.fhir.dstu3.model.OperationOutcome.IssueType; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Period; import org.hl7.fhir.dstu3.model.Quantity; +import org.hl7.fhir.dstu3.model.Quantity.QuantityComparator; import org.hl7.fhir.dstu3.model.Questionnaire; import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; -import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; -import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; -import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity; -import org.hl7.fhir.dstu3.model.OperationOutcome.IssueType; -import org.hl7.fhir.dstu3.model.Quantity.QuantityComparator; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -72,7 +72,6 @@ import org.mockito.ArgumentCaptor; import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; -import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.entity.TagTypeEnum; @@ -103,6 +102,7 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { @@ -167,7 +167,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { tl.add(new Coding().setSystem(methodName).setCode(methodName)); org.getMeta().getTag().addAll(tl); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map = new SearchParameterMap(); map.add("_language", new StringParam("EN_ca")); @@ -177,7 +177,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { map.add("_tag", new TokenParam(methodName, methodName)); assertEquals(1, myOrganizationDao.search(map).size()); - myOrganizationDao.delete(orgId); + myOrganizationDao.delete(orgId, new ServletRequestDetails()); map = new SearchParameterMap(); map.add("_language", new StringParam("EN_ca")); @@ -193,7 +193,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); o1.setValue(newCodeableConcept("testChoiceParam01CCS", "testChoiceParam01CCV")); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_CONCEPT, new TokenParam("testChoiceParam01CCS", "testChoiceParam01CCV")); @@ -207,7 +207,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testChoiceParam02"); o2.setValue(new Period().setStartElement(new DateTimeType("2001-01-01")).setEndElement(new DateTimeType("2001-01-03"))); - IIdType id2 = myObservationDao.create(o2).getId(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_DATE, new DateParam("2001-01-02")); @@ -221,7 +221,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testChoiceParamDateAlt02"); o2.setEffective(new DateTimeType("2015-03-08T11:11:11")); - IIdType id2 = myObservationDao.create(o2).getId(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId(); { Set found = myObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2001-01-02")); @@ -238,12 +238,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParamDateRange01"); o1.setEffective(new Period().setStartElement(new DateTimeType("2015-01-01T00:00:00Z")).setEndElement(new DateTimeType("2015-01-10T00:00:00Z"))); - IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testChoiceParamDateRange02"); o2.setEffective(new Period().setStartElement(new DateTimeType("2015-01-05T00:00:00Z")).setEndElement(new DateTimeType("2015-01-15T00:00:00Z"))); - IIdType id2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); { IBundleProvider found = myObservationDao.search(Observation.SP_DATE, new DateParam("ge2015-01-02T00:00:00Z")); @@ -278,7 +278,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o3 = new Observation(); o3.getCode().addCoding().setSystem("foo").setCode("testChoiceParam03"); o3.setValue(new Quantity(null, 123.01, "foo", "bar", "bar")); - IIdType id3 = myObservationDao.create(o3).getId().toUnqualifiedVersionless(); + IIdType id3 = myObservationDao.create(o3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_QUANTITY, new QuantityParam("123", "foo", "bar")); @@ -318,7 +318,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o3 = new Observation(); o3.getCode().addCoding().setSystem("foo").setCode("testChoiceParam03"); o3.setValue(new Quantity(QuantityComparator.GREATER_THAN, 123.0, "foo", "bar", "bar")); - IIdType id3 = myObservationDao.create(o3).getId(); + IIdType id3 = myObservationDao.create(o3, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_QUANTITY, new QuantityParam(">100", "foo", "bar")); @@ -378,7 +378,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o4 = new Observation(); o4.getCode().addCoding().setSystem("foo").setCode("testChoiceParam04"); o4.setValue(new StringType("testChoiceParam04Str")); - IIdType id4 = myObservationDao.create(o4).getId(); + IIdType id4 = myObservationDao.create(o4, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_STRING, new StringParam("testChoiceParam04Str")); @@ -432,7 +432,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.getMeta().addTag().setSystem(Constants.TAG_SUBSETTED_SYSTEM).setCode(Constants.TAG_SUBSETTED_CODE); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("subsetted")); @@ -462,7 +462,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { //@formatter:on NamingSystem res = myFhirCtx.newXmlParser().parseResource(NamingSystem.class, input); - IIdType id = myNamingSystemDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id = myNamingSystemDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertThat(toUnqualifiedVersionlessIdValues(myNamingSystemDao.search(NamingSystem.SP_NAME, new StringParam("NDF"))), contains(id.getValue())); } @@ -477,7 +477,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient resource = new Patient(); resource.addName().addFamily("My Name"); try { - dao.create(resource); + dao.create(resource, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Incorrect resource type detected for endpoint, found Patient but expected NamingSystem", e.getMessage()); @@ -491,7 +491,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/ABC"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not create resource with ID[ABC], ID must not be supplied")); @@ -505,7 +505,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/abc"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not create resource with ID[abc], ID must not be supplied")); @@ -519,7 +519,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); // Verify interceptor @@ -535,7 +535,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Hello"); - results = myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName); + results = myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); assertEquals(id.getIdPart(), results.getId().getIdPart()); assertFalse(results.getCreated().booleanValue()); @@ -546,7 +546,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Hello"); - results = myPatientDao.create(p); + results = myPatientDao.create(p, new ServletRequestDetails()); assertNotEquals(id.getIdPart(), results.getId().getIdPart()); assertTrue(results.getCreated().booleanValue()); @@ -556,7 +556,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Hello"); try { - myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName); + myPatientDao.create(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); fail(); } catch (PreconditionFailedException e) { assertThat(e.getMessage(), containsString("Failed to CREATE")); @@ -568,12 +568,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testCreateWithIllegalReference() { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); - IIdType id1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); try { Patient p = new Patient(); p.getManagingOrganization().setReferenceElement(id1); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Invalid reference found at path 'Patient.managingOrganization'. Resource type 'Observation' is not valid for this path", e.getMessage()); @@ -582,7 +582,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { try { Patient p = new Patient(); p.getManagingOrganization().setReferenceElement(new IdType("Organization", id1.getIdPart())); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Resource contains reference to Organization/" + id1.getIdPart() + " but resource with ID " + id1.getIdPart() + " is actually of type Observation", e.getMessage()); @@ -593,12 +593,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { o1 = new Observation(); o1.setId("testCreateWithIllegalReference"); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); - id1 = myObservationDao.update(o1).getId().toUnqualifiedVersionless(); + id1 = myObservationDao.update(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); try { Patient p = new Patient(); p.getManagingOrganization().setReferenceElement(id1); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Invalid reference found at path 'Patient.managingOrganization'. Resource type 'Observation' is not valid for this path", e.getMessage()); @@ -607,7 +607,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { try { Patient p = new Patient(); p.getManagingOrganization().setReferenceElement(new IdType("Organization", id1.getIdPart())); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { assertEquals("Resource contains reference to Organization/testCreateWithIllegalReference but resource with ID testCreateWithIllegalReference is actually of type Observation", e.getMessage()); @@ -620,7 +620,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01"); o1.setValue(newCodeableConcept("testChoiceParam01CCS", "testChoiceParam01CCV")); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); { IBundleProvider found = myObservationDao.search(Observation.SP_VALUE_CONCEPT, new TokenParam("testChoiceParam01CCS", "testChoiceParam01CCV")); @@ -641,7 +641,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.addName().addFamily("testSearchResourceLinkWithChainWithMultipleTypes01"); patient.setManagingOrganization(new Reference("Patient/99999999")); try { - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), StringContains.containsString("99999 not found")); @@ -656,7 +656,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.getManagingOrganization().setReference("Organization/"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Does not contain resource ID")); @@ -670,7 +670,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.getManagingOrganization().setReference("Blah/123"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Invalid resource reference")); @@ -684,7 +684,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.getManagingOrganization().setReference("123"); try { - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Does not contain resource type")); @@ -697,7 +697,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Encounter enc = new Encounter(); enc.addIdentifier().setSystem("testDatePeriodParam").setValue("02"); enc.getPeriod().getEndElement().setValueAsString("2001-01-02"); - myEncounterDao.create(enc); + myEncounterDao.create(enc, new ServletRequestDetails()); } SearchParameterMap params; List encs; @@ -741,7 +741,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { enc.addIdentifier().setSystem("testDatePeriodParam").setValue("03"); enc.getPeriod().getStartElement().setValueAsString("2001-01-02"); enc.getPeriod().getEndElement().setValueAsString("2001-01-03"); - myEncounterDao.create(enc); + myEncounterDao.create(enc, new ServletRequestDetails()); } SearchParameterMap params = new SearchParameterMap(); @@ -794,7 +794,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Encounter enc = new Encounter(); enc.addIdentifier().setSystem("testDatePeriodParam").setValue("01"); enc.getPeriod().getStartElement().setValueAsString("2001-01-02"); - myEncounterDao.create(enc); + myEncounterDao.create(enc, new ServletRequestDetails()); } SearchParameterMap params = new SearchParameterMap(); @@ -834,12 +834,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { String methodName = "testDeleteFailsIfIncomingLinks"; Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient patient = new Patient(); patient.addName().addFamily(methodName); patient.getManagingOrganization().setReferenceElement(orgId); - IIdType patId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map = new SearchParameterMap(); map.add("_id", new StringParam(orgId.getIdPart())); @@ -848,13 +848,13 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertThat(found, contains(orgId, patId)); try { - myOrganizationDao.delete(orgId); + myOrganizationDao.delete(orgId, new ServletRequestDetails()); fail(); } catch (ResourceVersionConflictException e) { assertThat(e.getMessage(), containsString("Delete failed because of constraint")); } - myPatientDao.delete(patId); + myPatientDao.delete(patId, new ServletRequestDetails()); map = new SearchParameterMap(); map.add("_id", new StringParam(orgId.getIdPart())); @@ -862,7 +862,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { found = toUnqualifiedVersionlessIds(myOrganizationDao.search(map)); assertThat(found, contains(orgId)); - myOrganizationDao.delete(orgId); + myOrganizationDao.delete(orgId, new ServletRequestDetails()); map = new SearchParameterMap(); map.add("_id", new StringParam(orgId.getIdPart())); @@ -874,7 +874,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { @Test public void testDeleteResource() { - int initialHistory = myPatientDao.history(null).size(); + int initialHistory = myPatientDao.history(null, new ServletRequestDetails()).size(); IIdType id1; IIdType id2; @@ -883,18 +883,18 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testDeleteResource").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_testDeleteResource").addGiven("John"); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { - Patient patient = myPatientDao.read(id2); + Patient patient = myPatientDao.read(id2, new ServletRequestDetails()); patient.addIdentifier().setSystem("ZZZZZZZ").setValue("ZZZZZZZZZ"); - id2b = myPatientDao.update(patient).getId(); + id2b = myPatientDao.update(patient, new ServletRequestDetails()).getId(); } ourLog.info("ID1:{} ID2:{} ID2b:{}", new Object[] { id1, id2, id2b }); @@ -903,32 +903,32 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { List patients = toList(myPatientDao.search(params)); assertEquals(2, patients.size()); - myPatientDao.delete(id1); + myPatientDao.delete(id1, new ServletRequestDetails()); patients = toList(myPatientDao.search(params)); assertEquals(1, patients.size()); - myPatientDao.read(id1); + myPatientDao.read(id1, new ServletRequestDetails()); try { - myPatientDao.read(id1.toVersionless()); + myPatientDao.read(id1.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } - IBundleProvider history = myPatientDao.history(null); + IBundleProvider history = myPatientDao.history(null, new ServletRequestDetails()); assertEquals(4 + initialHistory, history.size()); List resources = history.getResources(0, 4); assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) resources.get(0))); try { - myPatientDao.delete(id2); + myPatientDao.delete(id2, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { // good } - myPatientDao.delete(id2.toVersionless()); + myPatientDao.delete(id2.toVersionless(), new ServletRequestDetails()); patients = toList(myPatientDao.search(params)); assertEquals(0, patients.size()); @@ -940,17 +940,17 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testDeleteThenUndelete").addGiven("Joe"); - IIdType id = myPatientDao.create(patient).getId(); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId(); assertThat(id.getValue(), Matchers.endsWith("/_history/1")); // should be ok - myPatientDao.read(id.toUnqualifiedVersionless()); + myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()); // Delete it - myPatientDao.delete(id.toUnqualifiedVersionless()); + myPatientDao.delete(id.toUnqualifiedVersionless(), new ServletRequestDetails()); try { - myPatientDao.read(id.toUnqualifiedVersionless()); + myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // expected @@ -960,11 +960,11 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_testDeleteThenUndelete").addGiven("Joe"); patient.setId(id.toUnqualifiedVersionless()); - IIdType id2 = myPatientDao.update(patient).getId(); + IIdType id2 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); assertThat(id2.getValue(), endsWith("/_history/3")); - IIdType gotId = myPatientDao.read(id.toUnqualifiedVersionless()).getIdElement(); + IIdType gotId = myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()).getIdElement(); assertEquals(id2, gotId); } @@ -974,16 +974,16 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReferenceElement(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization.name=" + methodName); + myPatientDao.deleteByUrl("Patient?organization.name=" + methodName, new ServletRequestDetails()); assertGone(id); } @@ -995,20 +995,20 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Organization org = new Organization(); org.setName(methodName); org.addIdentifier().setSystem("http://example.com").setValue(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReferenceElement(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization.identifier=http://example.com|" + methodName); + myPatientDao.deleteByUrl("Patient?organization.identifier=http://example.com|" + methodName, new ServletRequestDetails()); assertGone(id); assertNotGone(orgId); - myOrganizationDao.deleteByUrl("Organization?identifier=http://example.com|" + methodName); + myOrganizationDao.deleteByUrl("Organization?identifier=http://example.com|" + methodName, new ServletRequestDetails()); assertGone(id); assertGone(orgId); @@ -1023,35 +1023,35 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReferenceElement(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization._tag=http://foo|term"); + myPatientDao.deleteByUrl("Patient?organization._tag=http://foo|term", new ServletRequestDetails()); assertGone(id); - myOrganizationDao.deleteByUrl("Organization?_tag=http://foo|term"); + myOrganizationDao.deleteByUrl("Organization?_tag=http://foo|term", new ServletRequestDetails()); try { - myOrganizationDao.read(orgId); + myOrganizationDao.read(orgId, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myPatientDao.deleteByUrl("Patient?organization._tag.identifier=http://foo|term"); + myPatientDao.deleteByUrl("Patient?organization._tag.identifier=http://foo|term", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: organization._tag.identifier", e.getMessage()); } try { - myOrganizationDao.deleteByUrl("Organization?_tag.identifier=http://foo|term"); + myOrganizationDao.deleteByUrl("Organization?_tag.identifier=http://foo|term", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: _tag.identifier", e.getMessage()); @@ -1069,12 +1069,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Organization org1 = new Organization(); org1.addIdentifier().setValue(methodName); - IIdType org1Id = myOrganizationDao.create(org1).getId().toUnqualifiedVersionless(); + IIdType org1Id = myOrganizationDao.create(org1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); p1.getManagingOrganization().setReferenceElement(org1Id); - IIdType patId1 = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + IIdType patId1 = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); /* * Org 2 has a name @@ -1083,37 +1083,37 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Organization org2 = new Organization(); org2.setName(methodName); org2.addIdentifier().setValue(methodName); - IIdType org2Id = myOrganizationDao.create(org2).getId().toUnqualifiedVersionless(); + IIdType org2Id = myOrganizationDao.create(org2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue(methodName); p2.getManagingOrganization().setReferenceElement(org2Id); - IIdType patId2 = myPatientDao.create(p2).getId().toUnqualifiedVersionless(); + IIdType patId2 = myPatientDao.create(p2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Pat ID 1 : {}", patId1); ourLog.info("Org ID 1 : {}", org1Id); ourLog.info("Pat ID 2 : {}", patId2); ourLog.info("Org ID 2 : {}", org2Id); - myPatientDao.deleteByUrl("Patient?organization.name:missing=true"); + myPatientDao.deleteByUrl("Patient?organization.name:missing=true", new ServletRequestDetails()); assertGone(patId1); assertNotGone(patId2); assertNotGone(org1Id); assertNotGone(org2Id); - myOrganizationDao.deleteByUrl("Organization?name:missing=true"); + myOrganizationDao.deleteByUrl("Organization?name:missing=true", new ServletRequestDetails()); assertGone(patId1); assertNotGone(patId2); assertGone(org1Id); assertNotGone(org2Id); - myPatientDao.deleteByUrl("Patient?organization.name:missing=false"); + myPatientDao.deleteByUrl("Patient?organization.name:missing=false", new ServletRequestDetails()); assertGone(patId1); assertGone(patId2); assertGone(org1Id); assertNotGone(org2Id); - myOrganizationDao.deleteByUrl("Organization?name:missing=false"); + myOrganizationDao.deleteByUrl("Organization?name:missing=false", new ServletRequestDetails()); assertGone(patId1); assertGone(patId2); assertGone(org1Id); @@ -1125,9 +1125,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { */ private void assertNotGone(IIdType theId) { if ("Patient".equals(theId.getResourceType())) { - myPatientDao.read(theId); + myPatientDao.read(theId, new ServletRequestDetails()); } else if ("Organization".equals(theId.getResourceType())) { - myOrganizationDao.read(theId); + myOrganizationDao.read(theId, new ServletRequestDetails()); } else { fail("No type"); } @@ -1153,35 +1153,35 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { org.getMeta().getProfile().add(new IdType("http://foo")); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReferenceElement(orgId); - IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", id); - myPatientDao.deleteByUrl("Patient?organization._profile=http://foo"); + myPatientDao.deleteByUrl("Patient?organization._profile=http://foo", new ServletRequestDetails()); assertGone(id); - myOrganizationDao.deleteByUrl("Organization?_profile=http://foo"); + myOrganizationDao.deleteByUrl("Organization?_profile=http://foo", new ServletRequestDetails()); try { - myOrganizationDao.read(orgId); + myOrganizationDao.read(orgId, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myPatientDao.deleteByUrl("Patient?organization._profile.identifier=http://foo"); + myPatientDao.deleteByUrl("Patient?organization._profile.identifier=http://foo", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: organization._profile.identifier", e.getMessage()); } try { - myOrganizationDao.deleteByUrl("Organization?_profile.identifier=http://foo"); + myOrganizationDao.deleteByUrl("Organization?_profile.identifier=http://foo", new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Invalid parameter chain: _profile.identifier", e.getMessage()); @@ -1195,29 +1195,29 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient?identifier=urn%3Asystem%7C" + methodName); - myPatientDao.deleteByUrl("Patient?identifier=urn%3Asystem%7C" + methodName); + myPatientDao.deleteByUrl("Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); try { - myPatientDao.read(id.toVersionless()); + myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // ok } try { - myPatientDao.read(new IdType("Patient/" + methodName)); + myPatientDao.read(new IdType("Patient/" + methodName), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // ok } - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(2, history.size()); assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 0).get(0))); @@ -1235,14 +1235,14 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("testHistoryByForcedId"); patient.addName().addFamily("Tester").addGiven("testHistoryByForcedId"); patient.setId("Patient/testHistoryByForcedId"); - idv1 = myPatientDao.update(patient).getId(); + idv1 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); patient.addName().addFamily("Tester").addGiven("testHistoryByForcedIdName2"); patient.setId(patient.getIdElement().toUnqualifiedVersionless()); - idv2 = myPatientDao.update(patient).getId(); + idv2 = myPatientDao.update(patient, new ServletRequestDetails()).getId(); } - List patients = toList(myPatientDao.history(idv1.toVersionless(), null)); + List patients = toList(myPatientDao.history(idv1.toVersionless(), null, new ServletRequestDetails())); assertTrue(patients.size() == 2); // Newest first assertEquals("Patient/testHistoryByForcedId/_history/2", patients.get(0).getIdElement().toUnqualified().getValue()); @@ -1256,7 +1256,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addName().addFamily(methodName); - IIdType id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Date middleDate = null; int halfSize = 50; @@ -1269,11 +1269,11 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } patient.setId(id); patient.getName().get(0).getFamily().get(0).setValue(methodName + "_i"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); } // By instance - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1282,7 +1282,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By type - history = myPatientDao.history(null); + history = myPatientDao.history(null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1291,7 +1291,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By server - history = mySystemDao.history(null); + history = mySystemDao.history(null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1304,7 +1304,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { */ // By instance - history = myPatientDao.history(id, middleDate); + history = myPatientDao.history(id, middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1313,7 +1313,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By type - history = myPatientDao.history(middleDate); + history = myPatientDao.history(middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1322,7 +1322,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By server - history = mySystemDao.history(middleDate); + history = mySystemDao.history(middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1334,13 +1334,13 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { * Now delete the most recent version and make sure everything still works */ - myPatientDao.delete(id.toVersionless()); + myPatientDao.delete(id.toVersionless(), new ServletRequestDetails()); fullSize++; halfSize++; // By instance - history = myPatientDao.history(id, null); + history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1349,7 +1349,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By type - history = myPatientDao.history(null); + history = myPatientDao.history(null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1358,7 +1358,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By server - history = mySystemDao.history(null); + history = mySystemDao.history(null, new ServletRequestDetails()); assertEquals(fullSize + 1, history.size()); for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1371,7 +1371,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { */ // By instance - history = myPatientDao.history(id, middleDate); + history = myPatientDao.history(id, middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1380,7 +1380,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By type - history = myPatientDao.history(middleDate); + history = myPatientDao.history(middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1389,7 +1389,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } // By server - history = mySystemDao.history(middleDate); + history = mySystemDao.history(middleDate, new ServletRequestDetails()); assertEquals(halfSize, history.size()); for (int i = 0; i < halfSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); @@ -1405,13 +1405,13 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addName().addFamily(methodName); - IIdType id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); - myPatientDao.delete(id); + myPatientDao.delete(id, new ServletRequestDetails()); patient.setId(id); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(3, history.size()); List entries = history.getResources(0, 3); ourLog.info("" + ((IAnyResource) entries.get(0)).getMeta().getLastUpdated()); @@ -1438,14 +1438,14 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester").addGiven("Joe"); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); assertNotNull(outcome.getId()); assertFalse(outcome.getId().isEmpty()); Date now = new Date(); { - Patient retrieved = myPatientDao.read(outcome.getId()); + Patient retrieved = myPatientDao.read(outcome.getId(), new ServletRequestDetails()); Date published = retrieved.getMeta().getLastUpdated(); assertTrue(published.before(now)); } @@ -1454,13 +1454,13 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { * This ID points to a patient, so we should not be able to return othe types with it */ try { - myEncounterDao.read(outcome.getId()); + myEncounterDao.read(outcome.getId(), new ServletRequestDetails()); fail(); } catch (IllegalArgumentException e) { // expected } try { - myEncounterDao.read(new IdType(outcome.getId().getIdPart())); + myEncounterDao.read(new IdType(outcome.getId().getIdPart()), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // expected @@ -1520,7 +1520,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.getMeta().addProfile(("http://profile/1")); patient.getMeta().addProfile(("http://profile/2")); - id = myPatientDao.create(patient).getId(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } assertTrue(id.hasVersionIdPart()); @@ -1529,9 +1529,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { * Create a second version */ - Patient pt = myPatientDao.read(id); + Patient pt = myPatientDao.read(id, new ServletRequestDetails()); pt.addName().addFamily("anotherName"); - myPatientDao.update(pt); + myPatientDao.update(pt, new ServletRequestDetails()); /* * Meta-Delete on previous version @@ -1541,7 +1541,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - Meta newMeta = myPatientDao.metaDeleteOperation(id.withVersion("1"), meta); + Meta newMeta = myPatientDao.metaDeleteOperation(id.withVersion("1"), meta, new ServletRequestDetails()); assertEquals(1, newMeta.getProfile().size()); assertEquals(1, newMeta.getSecurity().size()); assertEquals(1, newMeta.getTag().size()); @@ -1553,7 +1553,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { * Meta Read on Version */ - meta = myPatientDao.metaGetOperation(Meta.class, id.withVersion("1")); + meta = myPatientDao.metaGetOperation(Meta.class, id.withVersion("1"), new ServletRequestDetails()); assertEquals(1, meta.getProfile().size()); assertEquals(1, meta.getSecurity().size()); assertEquals(1, meta.getTag().size()); @@ -1564,7 +1564,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { /* * Meta-read on Version 2 */ - meta = myPatientDao.metaGetOperation(Meta.class, id.withVersion("2")); + meta = myPatientDao.metaGetOperation(Meta.class, id.withVersion("2"), new ServletRequestDetails()); assertEquals(2, meta.getProfile().size()); assertEquals(2, meta.getSecurity().size()); assertEquals(2, meta.getTag().size()); @@ -1572,7 +1572,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { /* * Meta-read on latest version */ - meta = myPatientDao.metaGetOperation(Meta.class, id.toVersionless()); + meta = myPatientDao.metaGetOperation(Meta.class, id.toVersionless(), new ServletRequestDetails()); assertEquals(2, meta.getProfile().size()); assertEquals(2, meta.getSecurity().size()); assertEquals(2, meta.getTag().size()); @@ -1586,7 +1586,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - newMeta = myPatientDao.metaAddOperation(id.withVersion("1"), meta); + newMeta = myPatientDao.metaAddOperation(id.withVersion("1"), meta, new ServletRequestDetails()); assertEquals(2, newMeta.getProfile().size()); assertEquals(2, newMeta.getSecurity().size()); assertEquals(2, newMeta.getTag().size()); @@ -1595,7 +1595,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { * Meta Read on Version */ - meta = myPatientDao.metaGetOperation(Meta.class, id.withVersion("1")); + meta = myPatientDao.metaGetOperation(Meta.class, id.withVersion("1"), new ServletRequestDetails()); assertEquals(2, meta.getProfile().size()); assertEquals(2, meta.getSecurity().size()); assertEquals(2, meta.getTag().size()); @@ -1609,7 +1609,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - newMeta = myPatientDao.metaDeleteOperation(id.toVersionless(), meta); + newMeta = myPatientDao.metaDeleteOperation(id.toVersionless(), meta, new ServletRequestDetails()); assertEquals(1, newMeta.getProfile().size()); assertEquals(1, newMeta.getSecurity().size()); assertEquals(1, newMeta.getTag().size()); @@ -1625,7 +1625,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta.addTag().setSystem("tag_scheme1").setCode("tag_code1"); meta.addProfile("http://profile/1"); meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1"); - newMeta = myPatientDao.metaAddOperation(id.toVersionless(), meta); + newMeta = myPatientDao.metaAddOperation(id.toVersionless(), meta, new ServletRequestDetails()); assertEquals(2, newMeta.getProfile().size()); assertEquals(2, newMeta.getSecurity().size()); assertEquals(2, newMeta.getTag().size()); @@ -1710,7 +1710,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { int initial = val.size(); Organization org = myFhirCtx.newJsonParser().parseResource(Organization.class, inputStr); - myOrganizationDao.create(org); + myOrganizationDao.create(org, new ServletRequestDetails()); val = myOrganizationDao.searchForIds("name", new StringParam("P")); assertEquals(initial + 1, val.size()); @@ -1725,7 +1725,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testPersistContactPoint"); patient.addTelecom().setValue("555-123-4567"); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); found = toList(myPatientDao.search(Patient.SP_TELECOM, new TokenParam(null, "555-123-4567"))); assertEquals(1 + initialSize2000, found.size()); @@ -1736,26 +1736,26 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testPersistResourceLink() { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("testPersistResourceLink01"); - IIdType patientId01 = myPatientDao.create(patient).getId(); + IIdType patientId01 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Patient patient02 = new Patient(); patient02.addIdentifier().setSystem("urn:system").setValue("testPersistResourceLink02"); - IIdType patientId02 = myPatientDao.create(patient02).getId(); + IIdType patientId02 = myPatientDao.create(patient02, new ServletRequestDetails()).getId(); Observation obs01 = new Observation(); obs01.setEffective(new DateTimeType(new Date())); obs01.setSubject(new Reference(patientId01)); - IIdType obsId01 = myObservationDao.create(obs01).getId(); + IIdType obsId01 = myObservationDao.create(obs01, new ServletRequestDetails()).getId(); Observation obs02 = new Observation(); obs02.setEffective(new DateTimeType(new Date())); obs02.setSubject(new Reference(patientId02)); - IIdType obsId02 = myObservationDao.create(obs02).getId(); + IIdType obsId02 = myObservationDao.create(obs02, new ServletRequestDetails()).getId(); // Create another type, that shouldn't be returned DiagnosticReport dr01 = new DiagnosticReport(); dr01.setSubject(new Reference(patientId01)); - IIdType drId01 = myDiagnosticReportDao.create(dr01).getId(); + IIdType drId01 = myDiagnosticReportDao.create(dr01, new ServletRequestDetails()).getId(); ourLog.info("P1[{}] P2[{}] O1[{}] O2[{}] D1[{}]", new Object[] { patientId01, patientId02, obsId01, obsId02, drId01 }); @@ -1784,7 +1784,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.setBirthDateElement(new DateType("2001-01-01")); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); found = toList(myPatientDao.search(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"))); assertEquals(1 + initialSize2000, found.size()); @@ -1804,7 +1804,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { obs.getCode().addCoding().setSystem("foo").setCode("testPersistSearchParamQuantity"); obs.setValue(new StringType("AAAABBBB")); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); List found = toList(myObservationDao.search("value-string", new StringParam("AAAABBBB"))); assertEquals(1, found.size()); @@ -1820,7 +1820,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { obs.getCode().addCoding().setSystem("foo").setCode("testPersistSearchParamQuantity"); obs.setValue(new Quantity(111)); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); List found = toList(myObservationDao.search("value-quantity", new QuantityParam(111))); assertEquals(1, found.size()); @@ -1840,7 +1840,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.getGenderElement().setValue(AdministrativeGender.MALE); patient.addName().addFamily("Tester").addGiven("JoetestPersistSearchParams"); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); assertNotNull(outcome.getId()); assertFalse(outcome.getId().isEmpty()); @@ -1885,10 +1885,10 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testQuestionnaireTitleGetsIndexed() { Questionnaire q = new Questionnaire(); q.setTitle("testQuestionnaireTitleGetsIndexedQ_TITLE"); - IIdType qid1 = myQuestionnaireDao.create(q).getId().toUnqualifiedVersionless(); + IIdType qid1 = myQuestionnaireDao.create(q, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); q = new Questionnaire(); q.setTitle("testQuestionnaireTitleGetsIndexedQ_NOTITLE"); - IIdType qid2 = myQuestionnaireDao.create(q).getId().toUnqualifiedVersionless(); + IIdType qid2 = myQuestionnaireDao.create(q, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); IBundleProvider results = myQuestionnaireDao.search("title", new StringParam("testQuestionnaireTitleGetsIndexedQ_TITLE")); assertEquals(1, results.size()); @@ -1901,14 +1901,14 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testRead() { Observation o1 = new Observation(); o1.getCode().addCoding().setSystem("foo").setCode("testRead"); - IIdType id1 = myObservationDao.create(o1).getId(); + IIdType id1 = myObservationDao.create(o1, new ServletRequestDetails()).getId(); /* * READ */ reset(myInterceptor); - Observation obs = myObservationDao.read(id1.toUnqualifiedVersionless()); + Observation obs = myObservationDao.read(id1.toUnqualifiedVersionless(), new ServletRequestDetails()); assertEquals(o1.getCode().getCoding().get(0).getCode(), obs.getCode().getCoding().get(0).getCode()); // Verify interceptor @@ -1923,7 +1923,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { */ assertTrue(id1.hasVersionIdPart()); // just to make sure.. reset(myInterceptor); - obs = myObservationDao.read(id1); + obs = myObservationDao.read(id1, new ServletRequestDetails()); assertEquals(o1.getCode().getCoding().get(0).getCode(), obs.getCode().getCoding().get(0).getCode()); // Verify interceptor @@ -1940,20 +1940,20 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testReadVorcedIdVersionHistory01"); p1.setId("testReadVorcedIdVersionHistory"); - IIdType p1id = new IdType(myPatientDao.update(p1).getId().getValue()); + IIdType p1id = new IdType(myPatientDao.update(p1, new ServletRequestDetails()).getId().getValue()); assertEquals("testReadVorcedIdVersionHistory", p1id.getIdPart()); p1.addIdentifier().setSystem("urn:system").setValue("testReadVorcedIdVersionHistory02"); p1.setId(p1id); - IIdType p1idv2 = myPatientDao.update(p1).getId(); + IIdType p1idv2 = myPatientDao.update(p1, new ServletRequestDetails()).getId(); assertEquals("testReadVorcedIdVersionHistory", p1idv2.getIdPart()); assertNotEquals(p1id.getValue(), p1idv2.getValue()); - Patient v1 = myPatientDao.read(p1id); + Patient v1 = myPatientDao.read(p1id, new ServletRequestDetails()); assertEquals(1, v1.getIdentifier().size()); - Patient v2 = myPatientDao.read(p1idv2); + Patient v2 = myPatientDao.read(p1idv2, new ServletRequestDetails()); assertEquals(2, v2.getIdentifier().size()); } @@ -1964,33 +1964,33 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient pat = new Patient(); pat.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(pat).getId(); + IIdType id = myPatientDao.create(pat, new ServletRequestDetails()).getId(); - assertEquals(methodName, myPatientDao.read(id).getIdentifier().get(0).getValue()); + assertEquals(methodName, myPatientDao.read(id, new ServletRequestDetails()).getIdentifier().get(0).getValue()); try { - myPatientDao.read(id.withVersion("0")); + myPatientDao.read(id.withVersion("0"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Version \"0\" is not valid for resource Patient/" + id.getIdPart(), e.getMessage()); } try { - myPatientDao.read(id.withVersion("2")); + myPatientDao.read(id.withVersion("2"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Version \"2\" is not valid for resource Patient/" + id.getIdPart(), e.getMessage()); } try { - myPatientDao.read(id.withVersion("H")); + myPatientDao.read(id.withVersion("H"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Version \"H\" is not valid for resource Patient/" + id.getIdPart(), e.getMessage()); } try { - myPatientDao.read(new IdType("Patient/9999999999999/_history/1")); + myPatientDao.read(new IdType("Patient/9999999999999/_history/1"), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { assertEquals("Resource Patient/9999999999999/_history/1 is not known", e.getMessage()); @@ -2004,31 +2004,31 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addName().addFamily(methodName); - IIdType id = myPatientDao.create(patient).getId().toVersionless(); - myPatientDao.delete(id); + IIdType id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toVersionless(); + myPatientDao.delete(id, new ServletRequestDetails()); assertGone(id); patient.setId(id); patient.addAddress().addLine("AAA"); - myPatientDao.update(patient); + myPatientDao.update(patient, new ServletRequestDetails()); Patient p; - p = myPatientDao.read(id); + p = myPatientDao.read(id, new ServletRequestDetails()); assertEquals(1, (p).getName().size()); - p = myPatientDao.read(id.withVersion("1")); + p = myPatientDao.read(id.withVersion("1"), new ServletRequestDetails()); assertEquals(1, (p).getName().size()); try { - myPatientDao.read(id.withVersion("2")); + myPatientDao.read(id.withVersion("2"), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } - p = myPatientDao.read(id.withVersion("3")); + p = myPatientDao.read(id.withVersion("3"), new ServletRequestDetails()); assertEquals(1, (p).getName().size()); } @@ -2041,13 +2041,13 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue(methodName); patient.addName().addFamily("Tester").addGiven("Joe"); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); Meta metaAdd = new Meta(); metaAdd.addTag().setSystem((String) null).setCode("Dog").setDisplay("Puppies"); metaAdd.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"); metaAdd.addProfile("http://profile/1"); - myPatientDao.metaAddOperation(id1, metaAdd); + myPatientDao.metaAddOperation(id1, metaAdd, new ServletRequestDetails()); } { Patient patient = new Patient(); @@ -2059,7 +2059,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.getMeta().addProfile(("http://profile/2")); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Device device = new Device(); @@ -2070,12 +2070,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { device.getMeta().addProfile("http://profile/3"); - myDeviceDao.create(device); + myDeviceDao.create(device, new ServletRequestDetails()); } Meta meta; - meta = myPatientDao.metaGetOperation(Meta.class); + meta = myPatientDao.metaGetOperation(Meta.class, new ServletRequestDetails()); List published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); @@ -2097,7 +2097,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertEquals("http://profile/1", profiles.get(0).getValue()); assertEquals("http://profile/2", profiles.get(1).getValue()); - meta = myPatientDao.metaGetOperation(Meta.class, id2); + meta = myPatientDao.metaGetOperation(Meta.class, id2, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2117,10 +2117,10 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { metaDel.addTag().setSystem((String) null).setCode("Dog"); metaDel.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1"); metaDel.addProfile("http://profile/1"); - myPatientDao.metaDeleteOperation(id1, metaDel); + myPatientDao.metaDeleteOperation(id1, metaDel, new ServletRequestDetails()); } - meta = myPatientDao.metaGetOperation(Meta.class); + meta = myPatientDao.metaGetOperation(Meta.class, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2152,7 +2152,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.getMeta().addProfile(("http://profile/1")); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); @@ -2163,7 +2163,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { patient.getMeta().addSecurity().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2"); patient.getMeta().addProfile("http://profile/2"); - id2 = myPatientDao.create(patient).getId(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Device device = new Device(); @@ -2171,12 +2171,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { device.getMeta().addTag("http://foo", "Foo", "Bars"); device.getMeta().addSecurity().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3"); device.getMeta().addProfile("http://profile/3"); - myDeviceDao.create(device); + myDeviceDao.create(device, new ServletRequestDetails()); } Meta meta; - meta = myPatientDao.metaGetOperation(Meta.class); + meta = myPatientDao.metaGetOperation(Meta.class, new ServletRequestDetails()); List published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); @@ -2198,7 +2198,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertEquals("http://profile/1", profiles.get(0).getValue()); assertEquals("http://profile/2", profiles.get(1).getValue()); - meta = myPatientDao.metaGetOperation(Meta.class, id2); + meta = myPatientDao.metaGetOperation(Meta.class, id2, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2213,11 +2213,11 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertEquals(1, profiles.size()); assertEquals("http://profile/2", profiles.get(0).getValue()); - myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog"); - myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1"); - myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1"); + myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1", new ServletRequestDetails()); - meta = myPatientDao.metaGetOperation(Meta.class); + meta = myPatientDao.metaGetOperation(Meta.class, new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -2239,12 +2239,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { String methodName = "testReverseIncludes"; Organization org = new Organization(); org.setName("X" + methodName + "X"); - IIdType orgId = myOrganizationDao.create(org).getId(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId(); Patient pat = new Patient(); pat.addName().addFamily("X" + methodName + "X"); pat.getManagingOrganization().setReferenceElement(orgId.toUnqualifiedVersionless()); - myPatientDao.create(pat); + myPatientDao.create(pat, new ServletRequestDetails()); SearchParameterMap map = new SearchParameterMap(); map.add(Organization.SP_NAME, new StringParam("X" + methodName + "X")); @@ -2264,7 +2264,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testSortByComposite() { Observation o = new Observation(); o.getCode().setText("testSortByComposite"); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); SearchParameterMap pm = new SearchParameterMap(); pm.setSort(new SortSpec(Observation.SP_CODE_VALUE_CONCEPT)); @@ -2282,24 +2282,24 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); p.addName().addFamily("testSortF1").addGiven("testSortG1"); p.setBirthDateElement(new DateType("2001-01-01")); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); // Create out of order p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); p.addName().addFamily("testSortF2").addGiven("testSortG2"); p.setBirthDateElement(new DateType("2001-01-03")); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); p.addName().addFamily("testSortF3").addGiven("testSortG3"); p.setBirthDateElement(new DateType("2001-01-02")); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue("testtestSortByDate"); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual; SearchParameterMap pm; @@ -2334,22 +2334,22 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system1").setValue(methodName); p.addName().addFamily(methodName); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName); p.addName().addFamily(methodName); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system3").setValue(methodName); p.addName().addFamily(methodName); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system4").setValue(methodName); p.addName().addFamily(methodName); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2382,7 +2382,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap map; @@ -2406,25 +2406,25 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.setId(methodName); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType idMethodName = myPatientDao.update(p).getId().toUnqualifiedVersionless(); + IIdType idMethodName = myPatientDao.update(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); assertEquals(methodName, idMethodName.getIdPart()); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2458,17 +2458,17 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Encounter e1 = new Encounter(); e1.addIdentifier().setSystem("foo").setValue(methodName); e1.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("min").setValue(4.0 * 24 * 60); - IIdType id1 = myEncounterDao.create(e1).getId().toUnqualifiedVersionless(); + IIdType id1 = myEncounterDao.create(e1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Encounter e3 = new Encounter(); e3.addIdentifier().setSystem("foo").setValue(methodName); e3.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(3.0); - IIdType id3 = myEncounterDao.create(e3).getId().toUnqualifiedVersionless(); + IIdType id3 = myEncounterDao.create(e3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Encounter e2 = new Encounter(); e2.addIdentifier().setSystem("foo").setValue(methodName); e2.getLength().setSystem(BaseHapiFhirDao.UCUM_NS).setCode("year").setValue(2.0); - IIdType id2 = myEncounterDao.create(e2).getId().toUnqualifiedVersionless(); + IIdType id2 = myEncounterDao.create(e2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2489,19 +2489,19 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { res = new Observation(); res.setValue(new Quantity().setSystem("sys1").setCode("code1").setValue(2L)); - IIdType id2 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id2 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new Observation(); res.setValue(new Quantity().setSystem("sys1").setCode("code1").setValue(1L)); - IIdType id1 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id1 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new Observation(); res.setValue(new Quantity().setSystem("sys1").setCode("code1").setValue(3L)); - IIdType id3 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id3 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new Observation(); res.setValue(new Quantity().setSystem("sys1").setCode("code1").setValue(4L)); - IIdType id4 = myObservationDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id4 = myObservationDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm = new SearchParameterMap(); pm.setSort(new SortSpec(Observation.SP_VALUE_QUANTITY)); @@ -2528,33 +2528,33 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { String methodName = "testSortByReference"; Organization o1 = new Organization(); - IIdType oid1 = myOrganizationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType oid1 = myOrganizationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Organization o2 = new Organization(); - IIdType oid2 = myOrganizationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType oid2 = myOrganizationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("testSortF1").addGiven("testSortG1"); p.getManagingOrganization().setReferenceElement(oid1); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("testSortF2").addGiven("testSortG2"); p.getManagingOrganization().setReferenceElement(oid2); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("testSortF3").addGiven("testSortG3"); p.getManagingOrganization().setReferenceElement(oid1); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.getManagingOrganization().setReferenceElement(oid2); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2590,22 +2590,22 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { String string = "testSortByString01"; p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("testSortF1").addGiven("testSortG1"); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); // Create out of order p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("testSortF3").addGiven("testSortG3"); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("testSortF2").addGiven("testSortG2"); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2643,22 +2643,22 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam1").addGiven("Giv1"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam2").addGiven("Giv1"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam2").addGiven("Giv2"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(string); p.addName().addFamily("Fam1").addGiven("Giv2"); - myPatientDao.create(p).getId().toUnqualifiedVersionless(); + myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List names; @@ -2704,19 +2704,19 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName + "1"); - IIdType id3 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id3 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system1").setValue(methodName + "2"); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system1").setValue(methodName + "1"); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system2").setValue(methodName + "2"); - IIdType id4 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id4 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm; List actual; @@ -2750,19 +2750,19 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testSortByUri() { ConceptMap res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://foo2"); - IIdType id2 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id2 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://foo1"); - IIdType id1 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id1 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://bar3"); - IIdType id3 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id3 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://bar4"); - IIdType id4 = myConceptMapDao.create(res).getId().toUnqualifiedVersionless(); + IIdType id4 = myConceptMapDao.create(res, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); SearchParameterMap pm = new SearchParameterMap(); pm.setSort(new SortSpec(ConceptMap.SP_DEPENDSON)); @@ -2782,15 +2782,15 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public void testStoreUnversionedResources() { Organization o1 = new Organization(); o1.getNameElement().setValue("AAA"); - IIdType o1id = myOrganizationDao.create(o1).getId(); + IIdType o1id = myOrganizationDao.create(o1, new ServletRequestDetails()).getId(); assertTrue(o1id.hasVersionIdPart()); Patient p1 = new Patient(); p1.addName().addFamily("AAAA"); p1.getManagingOrganization().setReferenceElement(o1id); - IIdType p1id = myPatientDao.create(p1).getId(); + IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId(); - p1 = myPatientDao.read(p1id); + p1 = myPatientDao.read(p1id, new ServletRequestDetails()); assertFalse(p1.getManagingOrganization().getReferenceElement().hasVersionIdPart()); assertEquals(o1id.toUnqualifiedVersionless(), p1.getManagingOrganization().getReferenceElement().toUnqualifiedVersionless()); @@ -2804,9 +2804,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Organization org = new Organization(); org.setName("測試醫院"); org.addIdentifier().setSystem("urn:system").setValue("testStoreUtf8Characters_01"); - IIdType orgId = myOrganizationDao.create(org).getId(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId(); - Organization returned = myOrganizationDao.read(orgId); + Organization returned = myOrganizationDao.read(orgId, new ServletRequestDetails()); String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); @@ -2826,7 +2826,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Set val = myOrganizationDao.searchForIds("name", new StringParam("P")); int initial = val.size(); - myOrganizationDao.create(org); + myOrganizationDao.create(org, new ServletRequestDetails()); val = myOrganizationDao.searchForIds("name", new StringParam("P")); assertEquals(initial + 0, val.size()); @@ -2864,12 +2864,12 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { profiles.add(new IdType("http://profile/2")); patient.getMeta().getProfile().addAll(profiles); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); IIdType patientId = outcome.getId(); assertNotNull(patientId); assertFalse(patientId.isEmpty()); - Patient retrieved = myPatientDao.read(patientId); + Patient retrieved = myPatientDao.read(patientId, new ServletRequestDetails()); ArrayList published = (ArrayList) retrieved.getMeta().getTag(); sort(published); assertEquals(2, published.size()); @@ -2927,7 +2927,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { myPatientDao.addTag(patientId, TagTypeEnum.TAG, "http://foo", "Cat", "Kittens"); myPatientDao.addTag(patientId, TagTypeEnum.TAG, "http://foo", "Cow", "Calves"); - retrieved = myPatientDao.read(patientId); + retrieved = myPatientDao.read(patientId, new ServletRequestDetails()); published = (ArrayList) retrieved.getMeta().getTag(); sort(published); assertEquals(3, published.size()); @@ -2974,7 +2974,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { Set val = myOrganizationDao.searchForIds("type", new TokenParam(subStr1, subStr2)); int initial = val.size(); - myOrganizationDao.create(org); + myOrganizationDao.create(org, new ServletRequestDetails()); val = myOrganizationDao.searchForIds("type", new TokenParam(subStr1, subStr2)); assertEquals(initial + 1, val.size()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java index 2fdd66e1b3d..0a6c20f15f3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java @@ -41,6 +41,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3UpdateTest.class); @@ -51,14 +52,14 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester").addGiven("Joe"); - MethodOutcome outcome = myPatientDao.create(patient); + MethodOutcome outcome = myPatientDao.create(patient, new ServletRequestDetails()); assertNotNull(outcome.getId()); assertFalse(outcome.getId().isEmpty()); assertEquals("1", outcome.getId().getVersionIdPart()); Date now = new Date(); - Patient retrieved = myPatientDao.read(outcome.getId()); + Patient retrieved = myPatientDao.read(outcome.getId(), new ServletRequestDetails()); InstantType updated = retrieved.getMeta().getLastUpdatedElement().copy(); assertTrue(updated.before(now)); @@ -66,7 +67,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { reset(myInterceptor); retrieved.getIdentifier().get(0).setValue("002"); - MethodOutcome outcome2 = myPatientDao.update(retrieved); + MethodOutcome outcome2 = myPatientDao.update(retrieved, new ServletRequestDetails()); assertEquals(outcome.getId().getIdPart(), outcome2.getId().getIdPart()); assertNotEquals(outcome.getId().getVersionIdPart(), outcome2.getId().getVersionIdPart()); assertEquals("2", outcome2.getId().getVersionIdPart()); @@ -81,7 +82,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { Date now2 = new Date(); - Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless()); + Patient retrieved2 = myPatientDao.read(outcome.getId().toVersionless(), new ServletRequestDetails()); assertEquals("2", retrieved2.getIdElement().getVersionIdPart()); assertEquals("002", retrieved2.getIdentifier().get(0).getValue()); @@ -95,7 +96,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { * Get history */ - IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null); + IBundleProvider historyBundle = myPatientDao.history(outcome.getId(), null, new ServletRequestDetails()); assertEquals(2, historyBundle.size()); @@ -121,7 +122,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -129,9 +130,9 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/" + methodName); - myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName); + myPatientDao.update(p, "Patient?identifier=urn%3Asystem%7C" + methodName, new ServletRequestDetails()); - p = myPatientDao.read(id.toVersionless()); + p = myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); assertThat(p.getIdElement().toVersionless().toString(), not(containsString("test"))); assertEquals(id.toVersionless(), p.getIdElement().toVersionless()); assertNotEquals(id, p.getIdElement()); @@ -147,10 +148,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); assertEquals("Patient/" + methodName, id.toUnqualifiedVersionless().getValue()); - p = myPatientDao.read(id); + p = myPatientDao.read(id, new ServletRequestDetails()); assertEquals(methodName, p.getIdentifier().get(0).getValue()); } @@ -161,7 +162,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.setId("0" + methodName); p.addName().addFamily(methodName); - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); } /** @@ -180,7 +181,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p1.getMeta().addSecurity("sec_scheme1", "sec_term1",null); p1.getMeta().addProfile("http://foo1"); - p1id = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } { Patient p1 = new Patient(); @@ -191,10 +192,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p1.getMeta().addSecurity("sec_scheme2", "sec_term2", null); p1.getMeta().addProfile("http://foo2"); - myPatientDao.update(p1); + myPatientDao.update(p1, new ServletRequestDetails()); } { - Patient p1 = myPatientDao.read(p1id); + Patient p1 = myPatientDao.read(p1id, new ServletRequestDetails()); List tagList = p1.getMeta().getTag(); Set secListValues = new HashSet(); for (Coding next : tagList) { @@ -218,12 +219,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2AAA"); p1.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2AAA"); - IIdType p1id = myPatientDao.create(p1).getId(); + IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId(); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2BBB"); p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB"); - myPatientDao.create(p2).getId(); + myPatientDao.create(p2, new ServletRequestDetails()).getId(); Set ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA")); assertEquals(1, ids.size()); @@ -231,7 +232,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { // Update the name p1.getName().get(0).getGiven().get(0).setValue("testUpdateMaintainsSearchParamsDstu2BBB"); - MethodOutcome update2 = myPatientDao.update(p1); + MethodOutcome update2 = myPatientDao.update(p1, new ServletRequestDetails()); IIdType p1id2 = update2.getId(); ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA")); @@ -241,10 +242,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { assertEquals(2, ids.size()); // Make sure vreads work - p1 = myPatientDao.read(p1id); + p1 = myPatientDao.read(p1id, new ServletRequestDetails()); assertEquals("testUpdateMaintainsSearchParamsDstu2AAA", p1.getName().get(0).getGivenAsSingleString()); - p1 = myPatientDao.read(p1id2); + p1 = myPatientDao.read(p1id2, new ServletRequestDetails()); assertEquals("testUpdateMaintainsSearchParamsDstu2BBB", p1.getName().get(0).getGivenAsSingleString()); } @@ -254,13 +255,13 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes"); p1.addName().addFamily("Tester").addGiven("testUpdateRejectsInvalidTypes"); - IIdType p1id = myPatientDao.create(p1).getId(); + IIdType p1id = myPatientDao.create(p1, new ServletRequestDetails()).getId(); Organization p2 = new Organization(); p2.getNameElement().setValue("testUpdateRejectsInvalidTypes"); try { p2.setId(new IdType("Organization/" + p1id.getIdPart())); - myOrganizationDao.update(p2); + myOrganizationDao.update(p2, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { // good @@ -268,7 +269,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { try { p2.setId(new IdType("Patient/" + p1id.getIdPart())); - myOrganizationDao.update(p2); + myOrganizationDao.update(p2, new ServletRequestDetails()); fail(); } catch (UnprocessableEntityException e) { ourLog.error("Good", e); @@ -290,12 +291,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { tl.add(new IdType("http://foo/bar")); patient.getMeta().getProfile().addAll(tl); - id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Do a read { - Patient patient = myPatientDao.read(id); + Patient patient = myPatientDao.read(id, new ServletRequestDetails()); List tl = patient.getMeta().getProfile(); assertEquals(1, tl.size()); assertEquals("http://foo/bar", tl.get(0).getValue()); @@ -315,12 +316,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { tl.add(new IdType("http://foo/bar")); patient.getMeta().getProfile().addAll(tl); - id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Do a read { - Patient patient = myPatientDao.read(id); + Patient patient = myPatientDao.read(id, new ServletRequestDetails()); List tl = patient.getMeta().getProfile(); assertEquals(1, tl.size()); assertEquals("http://foo/bar", tl.get(0).getValue()); @@ -337,12 +338,12 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { patient.getMeta().getProfile().clear(); patient.getMeta().getProfile().addAll(tl); - id = myPatientDao.update(patient).getId().toUnqualifiedVersionless(); + id = myPatientDao.update(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } // Do a read { - Patient patient = myPatientDao.read(id); + Patient patient = myPatientDao.read(id, new ServletRequestDetails()); List tl = patient.getMeta().getProfile(); assertEquals(1, tl.size()); assertEquals("http://foo/baz", tl.get(0).getValue()); @@ -357,7 +358,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/9999999999999999"); try { - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not create resource with ID[9999999999999999], no resource with this ID exists and clients may only")); @@ -371,7 +372,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/123:456"); try { - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertEquals("Can not process entity with ID[123:456], this is not a valid FHIR ID", e.getMessage()); @@ -385,7 +386,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.addName().addFamily("Hello"); p.setId("Patient/123"); try { - myPatientDao.update(p); + myPatientDao.update(p, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("clients may only assign IDs which contain at least one non-numeric")); @@ -398,11 +399,11 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p.addIdentifier().setSystem("urn:system").setValue("testCreateNumericIdFails"); p.addName().addFamily("Hello"); p.setId("Patient/123abc"); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); assertEquals("123abc", id.getIdPart()); assertEquals("1", id.getVersionIdPart()); - p = myPatientDao.read(id.toUnqualifiedVersionless()); + p = myPatientDao.read(id.toUnqualifiedVersionless(), new ServletRequestDetails()); assertEquals("Patient/123abc", p.getIdElement().toUnqualifiedVersionless().getValue()); assertEquals("Hello", p.getName().get(0).getFamily().get(0).getValue()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java index d679251b93f..36c8870c16d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java @@ -8,15 +8,15 @@ import java.io.IOException; import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.dstu3.model.ValueSet; -import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Ignore; @@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class); @@ -60,20 +61,20 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { private OperationOutcome doTestValidateResourceContainingProfileDeclaration(String methodName, EncodingEnum enc) throws IOException { Bundle vss = loadResourceFromClasspath(Bundle.class, "/org/hl7/fhir/instance/model/dstu3/valueset/valuesets.xml"); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning")); - myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes")); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-category"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-codes"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-methods"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-valueabsentreason"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-interpretation"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "body-site"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "referencerange-meaning"), new ServletRequestDetails()); + myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-relationshiptypes"), new ServletRequestDetails()); StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/org/hl7/fhir/instance/model/dstu3/profile/devicemetricobservation.profile.xml"); sd.setId(new IdType()); sd.setUrl("http://example.com/foo/bar/" + methodName); - myStructureDefinitionDao.create(sd); + myStructureDefinitionDao.create(sd, new ServletRequestDetails()); Observation input = new Observation(); input.getMeta().getProfile().add(new IdType(sd.getUrl())); @@ -90,7 +91,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { case JSON: encoded = myFhirCtx.newJsonParser().encodeResourceToString(input); try { - myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null); + myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails()); fail(); } catch (PreconditionFailedException e) { return (OperationOutcome) e.getOperationOutcome(); @@ -98,7 +99,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { case XML: encoded = myFhirCtx.newXmlParser().encodeResourceToString(input); try { - myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null); + myObservationDao.validate(input, null, encoded, EncodingEnum.XML, mode, null, new ServletRequestDetails()); fail(); } catch (PreconditionFailedException e) { return (OperationOutcome) e.getOperationOutcome(); @@ -123,7 +124,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { ValidationModeEnum mode = ValidationModeEnum.CREATE; String encoded = myFhirCtx.newJsonParser().encodeResourceToString(input); - MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null); + MethodOutcome outcome = myObservationDao.validate(input, null, encoded, EncodingEnum.JSON, mode, null, new ServletRequestDetails()); String ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome()); ourLog.info(ooString); @@ -140,14 +141,14 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { pat.addName().addFamily(methodName); try { - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("ID must not be populated")); } pat.setId(""); - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.CREATE, null, new ServletRequestDetails()); } @@ -158,12 +159,12 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { Patient pat = new Patient(); pat.setId("Patient/123"); pat.addName().addFamily(methodName); - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); pat.setId(""); try { - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("ID must be populated")); @@ -181,12 +182,12 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { Patient pat = new Patient(); pat.setId("Patient/123"); pat.addName().addFamily(methodName); - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); pat.setId(""); try { - myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null); + myPatientDao.validate(pat, null, null, null, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("ID must be populated")); @@ -200,16 +201,16 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { Organization org = new Organization(); org.setName(methodName); - IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); + IIdType orgId = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat = new Patient(); pat.addName().addFamily(methodName); pat.getManagingOrganization().setReference(orgId.getValue()); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); OperationOutcome outcome = null; try { - myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null); + myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails()); fail(); } catch (ResourceVersionConflictException e) { outcome = (OperationOutcome) e.getOperationOutcome(); @@ -221,9 +222,9 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { pat.setId(patId); pat.getManagingOrganization().setReference(""); - myPatientDao.update(pat); + myPatientDao.update(pat, new ServletRequestDetails()); - outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null).getOperationOutcome(); + outcome = (OperationOutcome) myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null, new ServletRequestDetails()).getOperationOutcome(); ooString = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(ooString); assertThat(ooString, containsString("Ok to delete")); @@ -248,7 +249,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { public void testValidateNewQuestionnaireFormat() throws Exception { String input =IOUtils.toString(FhirResourceDaoDstu3ValidateTest.class.getResourceAsStream("/questionnaire_dstu3.xml")); try { - MethodOutcome results = myQuestionnaireDao.validate(null, null, input, EncodingEnum.XML, ValidationModeEnum.UPDATE, null); + MethodOutcome results = myQuestionnaireDao.validate(null, null, input, EncodingEnum.XML, ValidationModeEnum.UPDATE, null, new ServletRequestDetails()); OperationOutcome oo = (OperationOutcome) results.getOperationOutcome(); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); } catch (PreconditionFailedException e) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java index 5ba5c8439ee..83c0f9a58df 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.springframework.transaction.annotation.Transactional; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirResourceDaoValueSetDstu3Test extends BaseJpaDstu3Test { @@ -37,7 +38,7 @@ public class FhirResourceDaoValueSetDstu3Test extends BaseJpaDstu3Test { public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.1.xml"); upload.setId(""); - myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless(); + myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java index f05d23163c6..0a0d9f53a70 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java @@ -17,6 +17,7 @@ import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test { @@ -32,7 +33,7 @@ public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test { patient.addName().addGiven("testSearchStringParamWithNonNormalized_h\u00F6ra"); patient.addName().addFamily("AAAS"); patient.addName().addFamily("CCC"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } Long id2; { @@ -41,13 +42,13 @@ public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test { patient.addName().addGiven("testSearchStringParamWithNonNormalized_HORA"); patient.addName().addFamily("AAAB"); patient.addName().addFamily("CCC"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } Long id3; { Organization org = new Organization(); org.setName("DDD"); - id3 = myOrganizationDao.create(org).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id3 = myOrganizationDao.create(org, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } SearchParameterMap map = new SearchParameterMap(); @@ -109,13 +110,13 @@ public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test { { Patient patient = new Patient(); patient.getText().setDivAsString("
AAAS

FOO

CCC
"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } Long id2; { Patient patient = new Patient(); patient.getText().setDivAsString("
AAAB

FOO

CCC
"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless().getIdPartAsLong(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless().getIdPartAsLong(); } SearchParameterMap map = new SearchParameterMap(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java index f11c2444729..76ff2f8b6ab 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java @@ -17,10 +17,8 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; import java.util.List; import org.apache.commons.io.IOUtils; @@ -64,6 +62,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { @@ -73,11 +72,11 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { public void testReindexing() { Patient p = new Patient(); p.addName().addFamily("family"); - final IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + final IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ValueSet vs = new ValueSet(); vs.setUrl("http://foo"); - myValueSetDao.create(vs); + myValueSetDao.create(vs, new ServletRequestDetails()); ResourceTable entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback() { @Override @@ -97,7 +96,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { }); assertEquals(null, entity.getIndexStatus()); - mySystemDao.performReindexingPass(null); + mySystemDao.performReindexingPass(null, new ServletRequestDetails()); entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback() { @Override @@ -108,7 +107,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals(Long.valueOf(1), entity.getIndexStatus()); // Just make sure this doesn't cause a choke - mySystemDao.performReindexingPass(100000); + mySystemDao.performReindexingPass(100000, new ServletRequestDetails()); // Try making the resource unparseable @@ -130,7 +129,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } }); - mySystemDao.performReindexingPass(null); + mySystemDao.performReindexingPass(null, new ServletRequestDetails()); entity = new TransactionTemplate(myTxManager).execute(new TransactionCallback() { @Override @@ -145,7 +144,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { @Test public void testSystemMetaOperation() { - Meta meta = mySystemDao.metaGetOperation(); + Meta meta = mySystemDao.metaGetOperation(new ServletRequestDetails()); List published = meta.getTag(); assertEquals(0, published.size()); @@ -160,7 +159,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { patient.getMeta().getSecurity().add(new Coding().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1")); patient.getMeta().getProfile().add(new IdType("http://profile/1")); - id1 = myPatientDao.create(patient).getId(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId(); } { Patient patient = new Patient(); @@ -171,10 +170,10 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { patient.getMeta().getSecurity().add(new Coding().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2")); patient.getMeta().getProfile().add(new IdType("http://profile/2")); - myPatientDao.create(patient); + myPatientDao.create(patient, new ServletRequestDetails()); } - meta = mySystemDao.metaGetOperation(); + meta = mySystemDao.metaGetOperation(new ServletRequestDetails()); published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); @@ -196,11 +195,11 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals("http://profile/1", profiles.get(0).getValue()); assertEquals("http://profile/2", profiles.get(1).getValue()); - myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog"); - myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1"); - myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1"); + myPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1", new ServletRequestDetails()); + myPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseHapiFhirDao.NS_JPA_PROFILE, "http://profile/1", new ServletRequestDetails()); - meta = mySystemDao.metaGetOperation(); + meta = mySystemDao.metaGetOperation(new ServletRequestDetails()); published = meta.getTag(); assertEquals(1, published.size()); assertEquals("http://foo", published.get(0).getSystem()); @@ -256,7 +255,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals("201 Created", respEntry.getStatus()); IdType createdId = new IdType(respEntry.getLocation()); assertEquals("Patient", createdId.getResourceType()); - myPatientDao.read(createdId); // shouldn't fail + myPatientDao.read(createdId, new ServletRequestDetails()); // shouldn't fail // Check GET respEntry = resp.getEntry().get(2).getResponse(); @@ -272,7 +271,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -300,7 +299,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1")); assertEquals("1", respEntry.getResponse().getEtag()); - o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement())); + o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()), new ServletRequestDetails()); assertEquals(id.toVersionless().getValue(), o.getSubject().getReference()); assertEquals("1", o.getIdElement().getVersionIdPart()); @@ -312,12 +311,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - id = myPatientDao.create(p).getId(); + id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); @@ -374,7 +373,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1")); assertEquals("1", respEntry.getResponse().getEtag()); - o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement())); + o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()), new ServletRequestDetails()); assertEquals(new IdType(patientId).toUnqualifiedVersionless().getValue(), o.getSubject().getReference()); } @@ -474,8 +473,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { mySystemDao.transaction(myRequestDetails, request); - myObservationDao.read(new IdType("Observation/a" + methodName)); - myPatientDao.read(new IdType("Patient/" + methodName)); + myObservationDao.read(new IdType("Observation/a" + methodName), new ServletRequestDetails()); + myPatientDao.read(new IdType("Patient/" + methodName), new ServletRequestDetails()); } @Test @@ -565,13 +564,13 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id1 = myPatientDao.create(p1).getId(); + IIdType id1 = myPatientDao.create(p1, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id1); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue(methodName); p2.setId("Patient/" + methodName); - IIdType id2 = myPatientDao.update(p2).getId(); + IIdType id2 = myPatientDao.update(p2, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id2); Bundle request = new Bundle(); @@ -579,8 +578,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { request.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient/" + id1.getIdPart()); request.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient/" + id2.getIdPart()); - myPatientDao.read(id1.toVersionless()); - myPatientDao.read(id2.toVersionless()); + myPatientDao.read(id1.toVersionless(), new ServletRequestDetails()); + myPatientDao.read(id2.toVersionless(), new ServletRequestDetails()); Bundle resp = mySystemDao.transaction(myRequestDetails, request); @@ -589,14 +588,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals("204 No Content", resp.getEntry().get(1).getResponse().getStatus()); try { - myPatientDao.read(id1.toVersionless()); + myPatientDao.read(id1.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myPatientDao.read(id2.toVersionless()); + myPatientDao.read(id2.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -613,20 +612,20 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", pid); Observation o1 = new Observation(); o1.getSubject().setReferenceElement(pid); - IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.addIdentifier().setValue(methodName); o2.getSubject().setReferenceElement(pid); - IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); - myPatientDao.read(pid); - myObservationDao.read(oid1); + myPatientDao.read(pid, new ServletRequestDetails()); + myObservationDao.read(oid1, new ServletRequestDetails()); // The target is Patient, so try with it first in the bundle Bundle request = new Bundle(); @@ -641,21 +640,21 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus()); try { - myPatientDao.read(pid); + myPatientDao.read(pid, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid1); + myObservationDao.read(oid1, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid2); + myObservationDao.read(oid2, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -672,20 +671,20 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType pid = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + IIdType pid = myPatientDao.create(p1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); ourLog.info("Created patient, got it: {}", pid); Observation o1 = new Observation(); o1.getSubject().setReferenceElement(pid); - IIdType oid1 = myObservationDao.create(o1).getId().toUnqualifiedVersionless(); + IIdType oid1 = myObservationDao.create(o1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation o2 = new Observation(); o2.addIdentifier().setValue(methodName); o2.getSubject().setReferenceElement(pid); - IIdType oid2 = myObservationDao.create(o2).getId().toUnqualifiedVersionless(); + IIdType oid2 = myObservationDao.create(o2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); - myPatientDao.read(pid); - myObservationDao.read(oid1); + myPatientDao.read(pid, new ServletRequestDetails()); + myObservationDao.read(oid1, new ServletRequestDetails()); // The target is Patient, so try with it last in the bundle Bundle request = new Bundle(); @@ -700,21 +699,21 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals("204 No Content", resp.getEntry().get(2).getResponse().getStatus()); try { - myPatientDao.read(pid); + myPatientDao.read(pid, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid1); + myObservationDao.read(oid1, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good } try { - myObservationDao.read(oid2); + myObservationDao.read(oid2, new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // good @@ -728,7 +727,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); @@ -741,20 +740,20 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", nextEntry.getResponse().getStatus()); try { - myPatientDao.read(id.toVersionless()); + myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // ok } try { - myPatientDao.read(new IdType("Patient/" + methodName)); + myPatientDao.read(new IdType("Patient/" + methodName), new ServletRequestDetails()); fail(); } catch (ResourceNotFoundException e) { // ok } - IBundleProvider history = myPatientDao.history(id, null); + IBundleProvider history = myPatientDao.history(id, null, new ServletRequestDetails()); assertEquals(2, history.size()); assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 0).get(0))); @@ -771,12 +770,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - id = myPatientDao.create(p).getId(); + id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -820,7 +819,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); Bundle request = new Bundle(); @@ -832,7 +831,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT + " No Content", res.getEntry().get(0).getResponse().getStatus()); try { - myPatientDao.read(id.toVersionless()); + myPatientDao.read(id.toVersionless(), new ServletRequestDetails()); fail(); } catch (ResourceGoneException e) { // ok @@ -871,7 +870,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertThat(resp.getEntry().get(1).getResponse().getLocation(), startsWith("Patient/temp6789/_history/")); assertThat(resp.getEntry().get(2).getResponse().getLocation(), startsWith("Organization/GHH/_history/")); - Patient p = myPatientDao.read(new IdType("Patient/a555-44-4444/_history/1")); + Patient p = myPatientDao.read(new IdType("Patient/a555-44-4444/_history/1"), new ServletRequestDetails()); assertEquals("Patient/temp6789", p.getLink().get(0).getOther().getReference()); } @@ -1024,14 +1023,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType idv1 = myPatientDao.update(p).getId(); + IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got id: {}", idv1); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Family Name"); p.setId("Patient/" + methodName); - IIdType idv2 = myPatientDao.update(p).getId(); + IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Updated patient, got id: {}", idv2); Bundle request = new Bundle(); @@ -1094,14 +1093,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType idv1 = myPatientDao.update(p).getId(); + IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got id: {}", idv1); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Family Name"); p.setId("Patient/" + methodName); - IIdType idv2 = myPatientDao.update(p).getId(); + IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Updated patient, got id: {}", idv2); Bundle request = new Bundle(); @@ -1139,14 +1138,14 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType idv1 = myPatientDao.update(p).getId(); + IIdType idv1 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got id: {}", idv1); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("Family Name"); p.setId("Patient/" + methodName); - IIdType idv2 = myPatientDao.update(p).getId(); + IIdType idv2 = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Updated patient, got id: {}", idv2); Bundle request = new Bundle(); @@ -1202,7 +1201,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -1231,7 +1230,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertThat(nextEntry.getResponse().getLocation(), not(emptyString())); nextEntry = resp.getEntry().get(1); - o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation())); + o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation()), new ServletRequestDetails()); assertEquals(id.toVersionless().getValue(), o.getSubject().getReference()); } @@ -1243,12 +1242,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - id = myPatientDao.create(p).getId(); + id = myPatientDao.create(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -1277,7 +1276,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addName().addFamily("Hello"); - IIdType id = myPatientDao.create(p).getId(); + IIdType id = myPatientDao.create(p, new ServletRequestDetails()).getId(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); @@ -1303,7 +1302,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertThat(patientId.getValue(), endsWith("/_history/1")); nextEntry = resp.getEntry().get(1); - o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation())); + o = myObservationDao.read(new IdType(nextEntry.getResponse().getLocation()), new ServletRequestDetails()); assertEquals(patientId.toVersionless().getValue(), o.getSubject().getReference()); } @@ -1316,7 +1315,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.setId("Patient/" + methodName); - IIdType id = myPatientDao.update(p).getId(); + IIdType id = myPatientDao.update(p, new ServletRequestDetails()).getId(); ourLog.info("Created patient, got it: {}", id); p = new Patient(); @@ -1344,7 +1343,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { nextEntry = resp.getEntry().get(1); assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", nextEntry.getResponse().getStatus()); - o = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation())); + o = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails()); assertEquals(id.toVersionless().getValue(), o.getSubject().getReference()); } @@ -1553,8 +1552,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation())); - o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation())); + o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails()); + o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails()); assertThat(o1.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart())); assertThat(o2.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart())); @@ -1596,8 +1595,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation())); - o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation())); + o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), new ServletRequestDetails()); + o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), new ServletRequestDetails()); assertThat(o1.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart())); assertThat(o2.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart())); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java index f3241e5ff50..cd48a7eafa4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java @@ -63,6 +63,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class ResourceProviderDstu1Test extends BaseJpaTest { @@ -421,7 +422,7 @@ public class ResourceProviderDstu1Test extends BaseJpaTest { // Read back directly from the DAO { - Organization returned = ourOrganizationDao.read(orgId); + Organization returned = ourOrganizationDao.read(orgId, new ServletRequestDetails()); String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index 3e6489cd653..61b2490c13d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -99,6 +99,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.UrlUtil; public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { @@ -123,19 +124,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { public void testEverythingInstanceWithContentFilter() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); - IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); + IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); - myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); + myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.getText().setDiv("
OBSTEXT1
"); @@ -143,19 +144,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { obs1.getCode().addCoding().setCode("CODE1"); obs1.setValue(new StringDt("obsvalue1")); obs1.getDevice().setReference(devId1); - IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReference(ptId1); obs2.getCode().addCoding().setCode("CODE2"); obs2.setValue(new StringDt("obsvalue2")); - IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs3 = new Observation(); obs3.getSubject().setReference(ptId2); obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringDt("obsvalue3")); - IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); + IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual; StringAndListParam param; @@ -553,12 +554,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("FAM1"); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("FAM2"); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); try { //@formatter:off @@ -973,16 +974,16 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { Medication med = new Medication(); med.getCode().setText(methodName); - IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); + IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat = new Patient(); pat.addAddress().addLine(methodName); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); MedicationOrder mo = new MedicationOrder(); mo.getPatient().setReference(patId); mo.setMedication(new ResourceReferenceDt(medId)); - IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); + IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); @@ -1491,13 +1492,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } //@formatter:off @@ -1714,7 +1715,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { public void testSearchWithInvalidSort() throws Exception { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); //@formatter:off ourClient .search() @@ -1957,7 +1958,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { // Read back directly from the DAO { - Organization returned = myOrganizationDao.read(orgId); + Organization returned = myOrganizationDao.read(orgId, new ServletRequestDetails()); String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java index c1fbf97c419..0a521d936e8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java @@ -23,6 +23,7 @@ import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2Test { @@ -34,7 +35,7 @@ public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2 public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml"); upload.setId(""); - myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless(); + myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java index 9ff43b3b3e5..46c9e6ef44b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java @@ -31,6 +31,7 @@ import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { @@ -177,7 +178,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { String methodName = "testSubscriptionDynamic"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); String criteria = "Observation?subject=Patient/" + pId.getIdPart(); DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.JSON); @@ -190,17 +191,17 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { sleepUntilPingCount(socket, 1); - mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId)); + mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails()); Observation obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -215,7 +216,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); sleepUntilPingCount(socket, 4); @@ -242,7 +243,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { String methodName = "testSubscriptionDynamic"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); String criteria = "Observation?subject=Patient/" + pId.getIdPart() + "&_format=xml"; DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.XML); @@ -255,18 +256,18 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { sleepUntilPingCount(socket, 1); - mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId)); + mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails()); Observation obs = new Observation(); ResourceMetadataKeyEnum.PROFILES.put(obs, Collections.singletonList(new IdDt("http://foo"))); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -281,7 +282,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); sleepUntilPingCount(socket, 4); @@ -307,26 +308,26 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { String methodName = "testSubscriptionResourcesAppear"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs = new Subscription(); ResourceMetadataKeyEnum.PROFILES.put(subs, Collections.singletonList(new IdDt("http://foo"))); subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatusEnum.ACTIVE); - String subsId = mySubscriptionDao.create(subs).getId().getIdPart(); + String subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().getIdPart(); Thread.sleep(100); Observation obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -344,7 +345,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { obs = new Observation(); obs.getSubject().setReference(pId); obs.setStatus(ObservationStatusEnum.FINAL); - IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); sleepUntilPingCount(socket, 2); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java index 6e61e7b07e2..9b18330883e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java @@ -51,6 +51,7 @@ import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class SystemProviderDstu2Test extends BaseJpaDstu2Test { @@ -190,18 +191,18 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); obs.getSubject().setReference(ptId); - IIdType obsId = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType obsId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.setId(obsId); obs.getSubject().setReference(ptId); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); - myObservationDao.update(obs); + myObservationDao.update(obs, new ServletRequestDetails()); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); CloseableHttpResponse http = ourHttpClient.execute(get); @@ -226,12 +227,12 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { public void testSuggestKeywordsInvalid() throws Exception { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReference(ptId); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords"); CloseableHttpResponse http = ourHttpClient.execute(get); @@ -379,7 +380,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { for (int i = 0; i < 20; i ++) { Patient p = new Patient(); p.addName().addFamily("PATIENT_" + i); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); } Bundle req = new Bundle(); @@ -403,7 +404,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { for (int i = 0; i < 20; i ++) { Patient p = new Patient(); p.addName().addFamily("PATIENT_" + i); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); } Bundle req = new Bundle(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 0b3c9c9450b..9722e72f087 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -101,6 +101,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.UrlUtil; public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { @@ -125,19 +126,19 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { public void testEverythingInstanceWithContentFilter() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId2 = myPatientDao.create(pt2).getId().toUnqualifiedVersionless(); + IIdType ptId2 = myPatientDao.create(pt2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); - IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); + IIdType devId1 = myDeviceDao.create(dev1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); - myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); + myDeviceDao.create(dev2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.getText().setDivAsString("
OBSTEXT1
"); @@ -145,19 +146,19 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { obs1.getCode().addCoding().setCode("CODE1"); obs1.setValue(new StringType("obsvalue1")); obs1.getDevice().setReferenceElement(devId1); - IIdType obsId1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obsId1 = myObservationDao.create(obs1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.getSubject().setReferenceElement(ptId1); obs2.getCode().addCoding().setCode("CODE2"); obs2.setValue(new StringType("obsvalue2")); - IIdType obsId2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless(); + IIdType obsId2 = myObservationDao.create(obs2, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs3 = new Observation(); obs3.getSubject().setReferenceElement(ptId2); obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringType("obsvalue3")); - IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); + IIdType obsId3 = myObservationDao.create(obs3, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); List actual; StringAndListParam param; @@ -569,12 +570,12 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("FAM1"); - IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id1 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("FAM2"); - IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType id2 = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); try { //@formatter:off @@ -989,16 +990,16 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Medication med = new Medication(); med.getCode().setText(methodName); - IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); + IIdType medId = myMedicationDao.create(med, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Patient pat = new Patient(); pat.addAddress().addLine(methodName); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + IIdType patId = myPatientDao.create(pat, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); MedicationOrder mo = new MedicationOrder(); mo.getPatient().setReferenceElement(patId); mo.setMedication(new Reference(medId)); - IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); + IIdType moId = myMedicationOrderDao.create(mo, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); @@ -1523,13 +1524,13 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id1 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } IIdType id2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + id2 = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } //@formatter:off @@ -1750,7 +1751,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { public void testSearchWithInvalidSort() throws Exception { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); //@formatter:off ourClient .search() @@ -1766,7 +1767,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { public void testSearchWithInvalidQuantityPrefix() throws Exception { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); - myObservationDao.create(o); + myObservationDao.create(o, new ServletRequestDetails()); try { //@formatter:off ourClient @@ -2036,7 +2037,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { // Read back directly from the DAO { - Organization returned = myOrganizationDao.read(orgId); + Organization returned = myOrganizationDao.read(orgId, new ServletRequestDetails()); String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java index e2c0b5301a5..8f2cc55b4de 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java @@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3Test { @@ -34,7 +35,7 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3 public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.1.xml"); upload.setId(""); - myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless(); + myExtensionalVsId = myValueSetDao.create(upload, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java index bcb24228f49..d0738e4ead8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java @@ -7,18 +7,17 @@ import static org.junit.Assert.fail; import org.hl7.fhir.dstu3.model.DecimalType; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Questionnaire; -import org.hl7.fhir.dstu3.model.QuestionnaireResponse; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; +import org.hl7.fhir.dstu3.model.QuestionnaireResponse; import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; -import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; -import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -52,11 +51,11 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource public void testCreateWithLocalReference() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Questionnaire q1 = new Questionnaire(); q1.addItem().setLinkId("link1").setType(QuestionnaireItemType.STRING); - IIdType qId = myQuestionnaireDao.create(q1).getId().toUnqualifiedVersionless(); + IIdType qId = myQuestionnaireDao.create(q1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); QuestionnaireResponse qr1 = new QuestionnaireResponse(); qr1.getQuestionnaire().setReferenceElement(qId); @@ -74,11 +73,11 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource public void testCreateWithAbsoluteReference() { Patient pt1 = new Patient(); pt1.addName().addFamily("Everything").addGiven("Arthur"); - IIdType ptId1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); + IIdType ptId1 = myPatientDao.create(pt1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Questionnaire q1 = new Questionnaire(); q1.addItem().setLinkId("link1").setType(QuestionnaireItemType.STRING); - IIdType qId = myQuestionnaireDao.create(q1).getId().toUnqualifiedVersionless(); + IIdType qId = myQuestionnaireDao.create(q1, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); QuestionnaireResponse qr1 = new QuestionnaireResponse(); qr1.getQuestionnaire().setReferenceElement(qId.withServerBase("http://example.com", "Questionnaire")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java index a350dda4bad..58bee660882 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java @@ -29,6 +29,7 @@ import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3 import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { @@ -163,7 +164,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { String methodName = "testSubscriptionDynamic"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); String criteria = "Observation?subject=Patient/" + pId.getIdPart(); DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.JSON); @@ -176,17 +177,17 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { sleepUntilPingCount(socket, 1); - mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId)); + mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails()); Observation obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -201,7 +202,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); sleepUntilPingCount(socket, 4); @@ -228,7 +229,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { String methodName = "testSubscriptionDynamic"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); String criteria = "Observation?subject=Patient/" + pId.getIdPart() + "&_format=xml"; DynamicEchoSocket socket = new DynamicEchoSocket(criteria, EncodingEnum.XML); @@ -241,18 +242,18 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { sleepUntilPingCount(socket, 1); - mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId)); + mySubscriptionDao.read(new IdDt("Subscription", socket.mySubsId), new ServletRequestDetails()); Observation obs = new Observation(); obs.getMeta().addProfile("http://foo"); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -267,7 +268,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); sleepUntilPingCount(socket, 4); @@ -293,26 +294,26 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { String methodName = "testSubscriptionResourcesAppear"; Patient p = new Patient(); p.addName().addFamily(methodName); - IIdType pId = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + IIdType pId = myPatientDao.create(p, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Subscription subs = new Subscription(); subs.getMeta().addProfile("http://foo"); subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?subject=Patient/" + pId.getIdPart()); subs.setStatus(SubscriptionStatus.ACTIVE); - String subsId = mySubscriptionDao.create(subs).getId().getIdPart(); + String subsId = mySubscriptionDao.create(subs, new ServletRequestDetails()).getId().getIdPart(); Thread.sleep(100); Observation obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId1 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId1 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId2 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId2 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Thread.sleep(100); @@ -330,7 +331,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { obs = new Observation(); obs.getSubject().setReferenceElement(pId); obs.setStatus(ObservationStatus.FINAL); - IIdType afterId3 = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType afterId3 = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); sleepUntilPingCount(socket, 2); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java index ee125db1c6a..1f780b40435 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java @@ -27,7 +27,10 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Bundle.BundleType; +import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; import org.hl7.fhir.dstu3.model.DecimalType; +import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.OperationDefinition; @@ -35,9 +38,6 @@ import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.dstu3.model.Bundle.BundleType; -import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; -import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.After; import org.junit.AfterClass; @@ -61,6 +61,7 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.validation.ResultSeverityEnum; public class SystemProviderDstu3Test extends BaseJpaDstu3Test { @@ -258,18 +259,18 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); obs.getSubject().setReferenceElement(ptId); - IIdType obsId = myObservationDao.create(obs).getId().toUnqualifiedVersionless(); + IIdType obsId = myObservationDao.create(obs, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); obs = new Observation(); obs.setId(obsId); obs.getSubject().setReferenceElement(ptId); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); - myObservationDao.update(obs); + myObservationDao.update(obs, new ServletRequestDetails()); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); CloseableHttpResponse http = ourHttpClient.execute(get); @@ -294,12 +295,12 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { public void testSuggestKeywordsInvalid() throws Exception { Patient patient = new Patient(); patient.addName().addFamily("testSuggest"); - IIdType ptId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + IIdType ptId = myPatientDao.create(patient, new ServletRequestDetails()).getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReferenceElement(ptId); obs.getCode().setText("ZXCVBNM ASDFGHJKL QWERTYUIOPASDFGHJKL"); - myObservationDao.create(obs); + myObservationDao.create(obs, new ServletRequestDetails()); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords"); CloseableHttpResponse http = ourHttpClient.execute(get); @@ -464,7 +465,7 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { for (int i = 0; i < 20; i ++) { Patient p = new Patient(); p.addName().addFamily("PATIENT_" + i); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); } Bundle req = new Bundle(); @@ -488,7 +489,7 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { for (int i = 0; i < 20; i ++) { Patient p = new Patient(); p.addName().addFamily("PATIENT_" + i); - myPatientDao.create(p); + myPatientDao.create(p, new ServletRequestDetails()); } Bundle req = new Bundle(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java index 404398e084e..08147038624 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java @@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; public class TerminologySvcImplTest extends BaseJpaDstu3Test { @@ -26,7 +27,7 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl("http://example.com/my_code_system"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); - IIdType id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + IIdType id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified(); ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); @@ -59,7 +60,7 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl("http://example.com/my_code_system"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); - IIdType id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + IIdType id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified(); ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); @@ -104,7 +105,7 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl("http://example.com/my_code_system"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); - IIdType id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + IIdType id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified(); ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); @@ -118,7 +119,7 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test { cs = new TermCodeSystemVersion(); TermConcept parentA = new TermConcept(cs, "ParentA"); cs.getConcepts().add(parentA); - id = myCodeSystemDao.update(codeSystem).getId().toUnqualified(); + id = myCodeSystemDao.update(codeSystem, new ServletRequestDetails()).getId().toUnqualified(); table = myResourceTableDao.findOne(id.getIdPartAsLong()); cs.setResource(table); cs.setResourceVersionId(table.getVersion()); @@ -128,7 +129,7 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test { codeSystem = new CodeSystem(); codeSystem.setUrl("http://example.com/my_code_system"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); - id = myCodeSystemDao.create(codeSystem).getId().toUnqualified(); + id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified(); table = myResourceTableDao.findOne(id.getIdPartAsLong()); cs.setResource(table); cs.setResourceVersionId(table.getVersion()); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java new file mode 100644 index 00000000000..a571f78fc93 --- /dev/null +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java @@ -0,0 +1,277 @@ +package ca.uhn.fhir.rest.server.interceptor; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.dstu2.composite.HumanNameDt; +import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum; +import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.UriDt; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Operation; +import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.method.RequestDetails; +import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.util.PortUtil; + +public class InterceptorUserDataMapDstu2Test { + + private static CloseableHttpClient ourClient; + private static final FhirContext ourCtx = FhirContext.forDstu2(); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(InterceptorUserDataMapDstu2Test.class); + private static int ourPort; + private static Server ourServer; + private static RestfulServer servlet; + private IServerInterceptor myInterceptor; + private final Object myKey = "KEY"; + private Map myMap; + private Set myMapCheckMethods; + private final Object myValue = "VALUE"; + + @Before + public void before() { + myInterceptor = mock(IServerInterceptor.class); + servlet.setInterceptors(Collections.singletonList(myInterceptor)); + } + + + @Before + public void beforePurgeMap() { + myMap = null; + myMapCheckMethods= new HashSet(); + } + + @Test + public void testException() throws Exception { + + IServerInterceptor interceptor = mock(IServerInterceptor.class, new MyInterceptorAnswer()); + + servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor)); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=foo"); + HttpResponse status = ourClient.execute(httpGet); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info(myMapCheckMethods.toString()); + assertThat(myMapCheckMethods, containsInAnyOrder("incomingRequestPreHandled", "handleException", "incomingRequestPostProcessed", "preProcessOutgoingException")); + } + + @Test + public void testRead() throws Exception { + + IServerInterceptor interceptor = mock(IServerInterceptor.class, new MyInterceptorAnswer()); + + servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor)); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); + HttpResponse status = ourClient.execute(httpGet); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info(myMapCheckMethods.toString()); + assertThat(myMapCheckMethods, containsInAnyOrder("incomingRequestPreHandled", "incomingRequestPostProcessed", "outgoingResponse")); + } + + protected void updateMapUsing(Map theUserData, Method theMethod) { + assertNotNull(theUserData); + if (myMap == null) { + myMap = theUserData; + myMap.put(myKey, myValue); + } else { + assertSame(myMap, theUserData); + assertEquals(myValue, myMap.get(myKey)); + } + myMapCheckMethods.add(theMethod.getName()); + } + + @AfterClass + public static void afterClass() throws Exception { + ourServer.stop(); + } + + @BeforeClass + public static void beforeClass() throws Exception { + ourPort = PortUtil.findFreePort(); + ourServer = new Server(ourPort); + + ServletHandler proxyHandler = new ServletHandler(); + servlet = new RestfulServer(ourCtx); + + servlet.setResourceProviders(new DummyPatientResourceProvider()); + servlet.setPlainProviders(new PlainProvider()); + + ServletHolder servletHolder = new ServletHolder(servlet); + proxyHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(proxyHandler); + ourServer.start(); + + PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); + HttpClientBuilder builder = HttpClientBuilder.create(); + builder.setConnectionManager(connectionManager); + ourClient = builder.build(); + + } + + public static class DummyPatientResourceProvider implements IResourceProvider { + + private Patient createPatient1() { + Patient patient = new Patient(); + patient.addIdentifier(); + patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); + patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); + patient.getIdentifier().get(0).setValue("00001"); + patient.addName(); + patient.getName().get(0).addFamily("Test"); + patient.getName().get(0).addGiven("PatientOne"); + patient.setGender(AdministrativeGenderEnum.MALE); + patient.getId().setValue("1"); + return patient; + } + + public Map getIdToPatient() { + Map idToPatient = new HashMap(); + { + Patient patient = createPatient1(); + idToPatient.put("1", patient); + } + { + Patient patient = new Patient(); + patient.getIdentifier().add(new IdentifierDt()); + patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); + patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); + patient.getIdentifier().get(0).setValue("00002"); + patient.getName().add(new HumanNameDt()); + patient.getName().get(0).addFamily("Test"); + patient.getName().get(0).addGiven("PatientTwo"); + patient.setGender(AdministrativeGenderEnum.FEMALE); + patient.getId().setValue("2"); + idToPatient.put("2", patient); + } + return idToPatient; + } + + /** + * Retrieve the resource by its identifier + * + * @param theId + * The resource identity + * @return The resource + */ + @Read() + public Patient getResourceById(@IdParam IdDt theId) { + if (theId.getIdPart().equals("EX")) { + throw new InvalidRequestException("FOO"); + } + String key = theId.getIdPart(); + Patient retVal = getIdToPatient().get(key); + return retVal; + } + + /** + * Retrieve the resource by its identifier + * + * @param theId + * The resource identity + * @return The resource + */ + @Search() + public List getResourceById(@RequiredParam(name = "_id") String theId) { + throw new InvalidRequestException("FOO"); + } + + @Override + public Class getResourceType() { + return Patient.class; + } + + @Operation(name = "$everything", idempotent = true) + public Bundle patientTypeOperation(@OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) { + + Bundle retVal = new Bundle(); + // Populate bundle with matching resources + return retVal; + } + + @Operation(name = "$everything", idempotent = true) + public Bundle patientTypeOperation(@IdParam IdDt theId, @OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) { + + Bundle retVal = new Bundle(); + // Populate bundle with matching resources + return retVal; + } + + } + + private final class MyInterceptorAnswer implements Answer { + @Override + public Object answer(InvocationOnMock theInvocation) throws Throwable { + int index = 0; + for (Class next : theInvocation.getMethod().getParameterTypes()) { + if (RequestDetails.class.isAssignableFrom(next)) { + updateMapUsing(((RequestDetails)theInvocation.getArguments()[index]).getUserData(), theInvocation.getMethod()); + } + if (ActionRequestDetails.class.isAssignableFrom(next)) { + updateMapUsing(((ActionRequestDetails)theInvocation.getArguments()[index]).getUserData(), theInvocation.getMethod()); + } + index++; + } + if (theInvocation.getMethod().getReturnType().equals(boolean.class)) { + return true; + } + return null; + } + } + + public static class PlainProvider { + + @Operation(name = "$everything", idempotent = true) + public Bundle patientTypeOperation(@OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) { + + Bundle retVal = new Bundle(); + // Populate bundle with matching resources + return retVal; + } + + } + +} diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm index 017ffcc2473..9bfb9a92490 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm @@ -45,7 +45,9 @@ public class ${className}ResourceProvider extends @Search() public ca.uhn.fhir.rest.server.IBundleProvider search( javax.servlet.http.HttpServletRequest theServletRequest, - + + ca.uhn.fhir.rest.method.RequestDetails theRequestDetails, + @Description(shortDefinition="The resource identity") @OptionalParam(name="_id") StringAndListParam theId, @@ -155,6 +157,7 @@ public class ${className}ResourceProvider extends paramMap.setIncludes(theIncludes); paramMap.setSort(theSort); paramMap.setCount(theCount); + paramMap.setRequestDetails(theRequestDetails); ca.uhn.fhir.rest.server.IBundleProvider retVal = getDao().search(paramMap); return retVal; diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e5b445fe831..452a17c3fd4 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -59,6 +59,18 @@ JPA server now supports :above and :below qualifiers on URI search params + + The RequestDetails and ActionRequestDetails objects which are passed to + server interceptor methods and may also be used as server provider method + arguments now has a new method + Map<String, String> getUserData() + ]]> + which can be used to pass data and objects between interceptor methods to + to providers. This can be useful, for instance, if an authorization + interceptor wants to pass the logged in user's details to other parts + of the server. + From 6cc60624c66b1fd1bf0ef50327ff3e7759591340 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 17 Feb 2016 08:50:35 -0500 Subject: [PATCH 3/6] Fix comment --- .../src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 0f49af83dba..e4aaff0ccd1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -805,9 +805,8 @@ public abstract class BaseHapiFhirDao implements IDao { * The entity being updated (Do not modify the entity! Undefined behaviour will occur!) * @param theTag * The tag - * @return Retturns true if the tag should be removed - * @see Updates to Tags, Profiles, and Security - * Labels for a description of the logic that the default behaviour folows. + * @return Returns true if the tag should be removed + * @see Updates to Tags, Profiles, and Security Labels for a description of the logic that the default behaviour folows. */ protected boolean shouldDroppedTagBeRemovedOnUpdate(ResourceTable theEntity, ResourceTag theTag) { if (theTag.getTag().getTagType() == TagTypeEnum.PROFILE) { From 43bdfc034588e71f3b30f311297f7558cc500c17 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 19 Feb 2016 06:21:05 -0500 Subject: [PATCH 4/6] Fix #297 - Resource not populated in ActionRequestDetails for validate method --- .../java/ca/uhn/fhir/context/FhirContext.java | 1 + .../fhir/rest/method/BaseMethodBinding.java | 3 +- .../rest/method/OperationMethodBinding.java | 44 +++-- .../fhir/rest/method/OperationParameter.java | 12 +- .../method/ValidateMethodBindingDstu2.java | 2 + .../uhn/fhir/rest/server/RestfulServer.java | 8 +- .../uhn/fhir/rest/server/InterceptorTest.java | 3 - .../rest/server/InterceptorDstu3Test.java | 157 ++++++++++++++++++ src/changes/changes.xml | 6 + src/site/xdoc/doc_rest_client_interceptor.xml | 2 +- 10 files changed, 210 insertions(+), 28 deletions(-) create mode 100644 hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index c4e6e832531..aa6c93ca8ef 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -243,6 +243,7 @@ public class FhirContext { * for extending the core library. */ public RuntimeResourceDefinition getResourceDefinition(IBaseResource theResource) { + Validate.notNull(theResource, "theResource must not be null"); return getResourceDefinition(theResource.getClass()); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java index 7448b4bf1b3..5b85b4c3549 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java @@ -303,8 +303,7 @@ public abstract class BaseMethodBinding implements IClientResponseHandler * The method params as generated by the specific method binding */ protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { - // TODO Auto-generated method stub - + // nothing by default } protected BaseServerResponseException processNon2xxResponseAndReturnExceptionToThrow(int theStatusCode, String theResponseMimeType, Reader theResponseReader) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java index 3161c865490..6c085f960dd 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.rest.method; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -50,11 +51,13 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ResourceParameter; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IRestfulServer; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; +import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.FhirTerser; public class OperationMethodBinding extends BaseResourceReturningMethodBinding { @@ -62,6 +65,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationMethodBinding.class); private boolean myCanOperateAtInstanceLevel; private boolean myCanOperateAtServerLevel; + private boolean myCanOperateAtTypeLevel; private String myDescription; private final boolean myIdempotent; private final Integer myIdParamIndex; @@ -69,7 +73,6 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { private final RestOperationTypeEnum myOtherOperatiopnType; private List myReturnParams; private final ReturnTypeEnum myReturnType; - private boolean myCanOperateAtTypeLevel; protected OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, boolean theIdempotent, String theOperationName, Class theOperationType, OperationParam[] theReturnParams) { @@ -86,7 +89,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { } else { myCanOperateAtTypeLevel = true; } - + Description description = theMethod.getAnnotation(Description.class); if (description != null) { myDescription = description.formalDefinition(); @@ -179,16 +182,16 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { return myName; } - @Override - public RestOperationTypeEnum getRestOperationType() { - return myOtherOperatiopnType; - } - @Override protected BundleTypeEnum getResponseBundleType() { return BundleTypeEnum.COLLECTION; } + @Override + public RestOperationTypeEnum getRestOperationType() { + return myOtherOperatiopnType; + } + public List getReturnParams() { return Collections.unmodifiableList(myReturnParams); } @@ -211,7 +214,13 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { if (!myName.equals(theRequest.getOperation())) { return false; } - + + RequestTypeEnum requestType = theRequest.getRequestType(); + if (requestType != RequestTypeEnum.GET && requestType != RequestTypeEnum.POST) { + // Operations can only be invoked with GET and POST + return false; + } + boolean requestHasId = theRequest.getId() != null; if (requestHasId) { if (isCanOperateAtInstanceLevel() == false) { @@ -246,9 +255,9 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { } @Override - public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException { + public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException { if (theRequest.getRequestType() == RequestTypeEnum.POST) { - // always ok + // all good } else if (theRequest.getRequestType() == RequestTypeEnum.GET) { if (!myIdempotent) { String message = getContext().getLocalizer().getMessage(OperationMethodBinding.class, "methodNotSupported", theRequest.getRequestType(), RequestTypeEnum.POST.name()); @@ -273,6 +282,15 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { return retVal; } + @Override + public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { + if (theRequest.getRequestType() == RequestTypeEnum.POST) { + IBaseResource requestContents = ResourceParameter.loadResourceFromRequest(theRequest, this, null); + theRequest.getUserData().put(OperationParameter.REQUEST_CONTENTS_USERDATA_KEY, requestContents); + } + return super.invokeServer(theServer, theRequest); + } + public boolean isCanOperateAtInstanceLevel() { return this.myCanOperateAtInstanceLevel; } @@ -285,6 +303,12 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { return myIdempotent; } + @Override + protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { + super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); + theDetails.setResource((IBaseResource) theRequestDetails.getUserData().get(OperationParameter.REQUEST_CONTENTS_USERDATA_KEY)); + } + public void setDescription(String theDescription) { myDescription = theDescription; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java index 8f0847acd3d..9a8cecca753 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java @@ -50,7 +50,6 @@ import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.param.CollectionBinder; import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ResourceParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; @@ -59,6 +58,8 @@ import ca.uhn.fhir.util.ParametersUtil; public class OperationParameter implements IParameter { + static final String REQUEST_CONTENTS_USERDATA_KEY = OperationParam.class.getName() + "_PARSED_RESOURCE"; + private IConverter myConverter; @SuppressWarnings("rawtypes") private Class myInnerCollectionType; @@ -210,14 +211,7 @@ public class OperationParameter implements IParameter { FhirContext ctx = theRequest.getServer().getFhirContext(); - if (theRequest.getRequestType() == RequestTypeEnum.GET) { - return null; - } - - // Class wantedResourceType = theMethodBinding.getContext().getResourceDefinition("Parameters").getImplementingClass(); - Class wantedResourceType = null; - IBaseResource requestContents = ResourceParameter.loadResourceFromRequest(theRequest, theMethodBinding, wantedResourceType); - + IBaseResource requestContents = (IBaseResource) theRequest.getUserData().get(REQUEST_CONTENTS_USERDATA_KEY); RuntimeResourceDefinition def = ctx.getResourceDefinition(requestContents); if (def.getName().equals("Parameters")) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java index f42fbb0019b..8d09e42f4b3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java @@ -34,6 +34,8 @@ import ca.uhn.fhir.rest.client.BaseHttpClientInvocation; import ca.uhn.fhir.rest.param.ResourceParameter; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; +import ca.uhn.fhir.rest.server.IRestfulServer; +import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.util.ParametersUtil; public class ValidateMethodBindingDstu2 extends OperationMethodBinding { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 42d61e7fd2d..73e004b83b9 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -621,10 +621,12 @@ public class RestfulServer extends HttpServlet implements IRestfulServer opTypeCapt = ArgumentCaptor.forClass(RestOperationTypeEnum.class); + ArgumentCaptor arTypeCapt = ArgumentCaptor.forClass(ActionRequestDetails.class); + order.verify(myInterceptor1, times(1)).incomingRequestPreHandled(opTypeCapt.capture(), arTypeCapt.capture()); + order.verify(myInterceptor2, times(1)).incomingRequestPreHandled(any(RestOperationTypeEnum.class), any(ActionRequestDetails.class)); + order.verify(myInterceptor2, times(1)).outgoingResponse(any(RequestDetails.class), any(IResource.class)); + order.verify(myInterceptor1, times(1)).outgoingResponse(any(RequestDetails.class), any(IResource.class)); + verifyNoMoreInteractions(myInterceptor1); + verifyNoMoreInteractions(myInterceptor2); + + assertEquals(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, opTypeCapt.getValue()); + assertNotNull(arTypeCapt.getValue().getResource()); + } + + @AfterClass + public static void afterClass() throws Exception { + ourServer.stop(); + } + + @Before + public void before() { + myInterceptor1 = mock(IServerInterceptor.class); + myInterceptor2 = mock(IServerInterceptor.class); + servlet.setInterceptors(myInterceptor1, myInterceptor2); + } + + @BeforeClass + public static void beforeClass() throws Exception { + ourPort = PortUtil.findFreePort(); + ourServer = new Server(ourPort); + + DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); + + ServletHandler proxyHandler = new ServletHandler(); + servlet = new RestfulServer(ourCtx); + servlet.setResourceProviders(patientProvider); + ServletHolder servletHolder = new ServletHolder(servlet); + proxyHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(proxyHandler); + ourServer.start(); + + PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); + HttpClientBuilder builder = HttpClientBuilder.create(); + builder.setConnectionManager(connectionManager); + ourClient = builder.build(); + + } + + public static class DummyPatientResourceProvider implements IResourceProvider { + + @Validate() + public MethodOutcome validate(@ResourceParam Patient theResource) { + return new MethodOutcome(); + } + + @Override + public Class getResourceType() { + return Patient.class; + } + } + +} diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 452a17c3fd4..09ad8e462be 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -71,6 +71,12 @@ interceptor wants to pass the logged in user's details to other parts of the server. + + IServerInterceptor#incomingRequestPreHandled() is called + for a @Validate method, the resource was not populated in the + ActionRequestDetails argument. Thanks to Ravi Kuchi for reporting! + ]]> + diff --git a/src/site/xdoc/doc_rest_client_interceptor.xml b/src/site/xdoc/doc_rest_client_interceptor.xml index eecdbeaa4b2..b9df59a7692 100644 --- a/src/site/xdoc/doc_rest_client_interceptor.xml +++ b/src/site/xdoc/doc_rest_client_interceptor.xml @@ -92,7 +92,7 @@

- + From 6ce4056f7a7e28867d20d3068ae17423ea66370a Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 19 Feb 2016 06:40:07 -0500 Subject: [PATCH 5/6] Fix #298 - Don't handle /metadata for methods other than GET --- .../rest/method/ConformanceMethodBinding.java | 13 ++- .../uhn/fhir/rest/server/RestfulServer.java | 4 +- .../fhir/rest/server/MetadataDstu3Test2.java | 108 ++++++++++++++++++ src/changes/changes.xml | 7 ++ 4 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ConformanceMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ConformanceMethodBinding.java index 66152874245..34a617fd321 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ConformanceMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ConformanceMethodBinding.java @@ -35,6 +35,7 @@ import ca.uhn.fhir.rest.server.IRestfulServer; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding { @@ -83,8 +84,16 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding return true; } - if (theRequest.getRequestType() == RequestTypeEnum.GET && "metadata".equals(theRequest.getOperation())) { - return true; + if (theRequest.getResourceName() != null) { + return false; + } + + if ("metadata".equals(theRequest.getOperation())) { + if (theRequest.getRequestType() == RequestTypeEnum.GET) { + return true; + } else { + throw new MethodNotAllowedException("/metadata request must use HTTP GET", RequestTypeEnum.GET); + } } return false; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 73e004b83b9..0f4b409cf23 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -223,7 +223,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer resourceMethod = null; String resourceName = requestDetails.getResourceName(); - if (Constants.URL_TOKEN_METADATA.equals(resourceName) || requestType == RequestTypeEnum.OPTIONS) { + if (myServerConformanceMethod.incomingServerRequestMatchesMethod(requestDetails)) { resourceMethod = myServerConformanceMethod; } else if (resourceName == null) { resourceBinding = myServerBinding; @@ -1396,7 +1396,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer 0 && (nextString.charAt(0) == '_' || nextString.charAt(0) == '$'); + return nextString.length() > 0 && (nextString.charAt(0) == '_' || nextString.charAt(0) == '$' || nextString.equals(Constants.URL_TOKEN_METADATA)); } public static boolean requestIsBrowser(HttpServletRequest theRequest) { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java new file mode 100644 index 00000000000..8af0b4c4b9d --- /dev/null +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java @@ -0,0 +1,108 @@ +package ca.uhn.fhir.rest.server; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.hl7.fhir.dstu3.model.Patient; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Validate; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.util.PortUtil; + +public class MetadataDstu3Test2 { + + private static CloseableHttpClient ourClient; + private static int ourPort; + private static Server ourServer; + private static RestfulServer servlet; + private static final FhirContext ourCtx = FhirContext.forDstu3(); + + @Test + public void testHttpMethods() throws Exception { + String output; + + HttpRequestBase httpPost = new HttpGet("http://localhost:" + ourPort + "/metadata"); + HttpResponse status = ourClient.execute(httpPost); + output = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(output, containsString("", output); + + /* + * There is no @read on the RP below, so this should fail. Otherwise it + * would be interpreted as a read on ID "metadata" + */ + httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient/metadata"); + status = ourClient.execute(httpPost); + output = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + assertEquals(400, status.getStatusLine().getStatusCode()); + } + + @AfterClass + public static void afterClass() throws Exception { + ourServer.stop(); + } + + @BeforeClass + public static void beforeClass() throws Exception { + ourPort = PortUtil.findFreePort(); + ourServer = new Server(ourPort); + + DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); + + ServletHandler proxyHandler = new ServletHandler(); + servlet = new RestfulServer(ourCtx); + servlet.setResourceProviders(patientProvider); + ServletHolder servletHolder = new ServletHolder(servlet); + proxyHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(proxyHandler); + ourServer.start(); + + PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); + HttpClientBuilder builder = HttpClientBuilder.create(); + builder.setConnectionManager(connectionManager); + ourClient = builder.build(); + + } + + public static class DummyPatientResourceProvider implements IResourceProvider { + + @Validate() + public MethodOutcome validate(@ResourceParam Patient theResource) { + return new MethodOutcome(); + } + + @Override + public Class getResourceType() { + return Patient.class; + } + } + +} diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 09ad8e462be..6509a2d9d09 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,6 +77,13 @@ ActionRequestDetails argument. Thanks to Ravi Kuchi for reporting! ]]>
+ + [baseUrl]/metadata with an HTTP method + other than GET (e.g. POST, PUT) should result in an HTTP 405. Thanks to + Michael Lawley for reporting! + ]]> +
From fd2eaff12d8eeba1f464cd23d3bd3066a31d77f6 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 19 Feb 2016 06:53:23 -0500 Subject: [PATCH 6/6] Fix javadoc --- .../src/main/java/ca/uhn/fhir/model/primitive/IdDt.java | 2 +- .../src/main/java/org/hl7/fhir/dstu3/model/IdType.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java index 171a7f7104a..25f66df59dd 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java @@ -49,7 +49,7 @@ import ca.uhn.fhir.util.UrlUtil; * limit of 36 characters. *

*

- * regex: [a-z0-9\-\.]{1,36} + * regex: [a-z-Z0-9\-\.]{1,36} *

*/ @DatatypeDef(name = "id", profileOf=StringDt.class) diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/IdType.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/IdType.java index c32a5849a91..8bb8dc5bafa 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/IdType.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/IdType.java @@ -79,7 +79,7 @@ import ca.uhn.fhir.model.api.annotation.DatatypeDef; * identity on objects it creates as a convenience. *

*

- * Regex for ID: [a-z0-9\-\.]{1,36} + * Regex for ID: [a-zA-Z0-9\-\.]{1,36} *

*/ @DatatypeDef(name = "id", profileOf=StringType.class)