diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoObservationDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoObservationDstu3.java index 3cb0bb1f2f0..993ce07bdf2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoObservationDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoObservationDstu3.java @@ -24,7 +24,6 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoObservation; import ca.uhn.fhir.jpa.dao.lastn.ObservationLastNIndexPersistDstu3Svc; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; -import ca.uhn.fhir.jpa.model.entity.ResourceLink; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum; @@ -41,9 +40,9 @@ 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 org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.Reference; import org.springframework.beans.factory.annotation.Autowired; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Collection; import java.util.Collections; @@ -93,18 +92,9 @@ public class FhirResourceDaoObservationDstu3 extends BaseHapiFhirResourceDao myResourceLinks = retVal.getResourceLinks(); - Long subjectID = null; - for (ResourceLink resourceLink : myResourceLinks) { - if(resourceLink.getSourcePath().equals("Observation.subject")) { - subjectID = resourceLink.getTargetResourcePid(); - } - } - if (subjectID != null) { - myObservationLastNIndexPersistDstu3Svc.indexObservation(observation, subjectID.toString()); - } else { - myObservationLastNIndexPersistDstu3Svc.indexObservation(observation); - } + Reference subjectReference = observation.getSubject(); + String subjectID = subjectReference.getIdElement().getValue(); + myObservationLastNIndexPersistDstu3Svc.indexObservation(observation, subjectID); } return retVal; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistDstu3Svc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistDstu3Svc.java index 66ccd325db4..f02743db2fd 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistDstu3Svc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistDstu3Svc.java @@ -78,10 +78,4 @@ public class ObservationLastNIndexPersistDstu3Svc { } - // TODO: Remove this once Unit tests are updated. - public void indexObservation(Observation theObservation) { - String subjectId = "Patient/" + theObservation.getSubject().getReference(); - - indexObservation(theObservation, subjectId); - } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR4Svc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR4Svc.java index 09f87f8e9b3..ec7a4afe6f9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR4Svc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR4Svc.java @@ -79,10 +79,4 @@ public class ObservationLastNIndexPersistR4Svc { } - // TODO: Remove this once Unit tests are updated. - public void indexObservation(Observation theObservation) { - String subjectId = "Patient/" + theObservation.getSubject().getReference(); - - indexObservation(theObservation, subjectId); - } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR5Svc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR5Svc.java index e37d7a154b2..4365740fc91 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR5Svc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/ObservationLastNIndexPersistR5Svc.java @@ -78,10 +78,4 @@ public class ObservationLastNIndexPersistR5Svc { } - // TODO: Remove this once Unit tests are updated. - public void indexObservation(Observation theObservation) { - String subjectId = "Patient/" + theObservation.getSubject().getReference(); - - indexObservation(theObservation, subjectId); - } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/entity/ObservationIndexedSearchParamLastNEntity.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/entity/ObservationIndexedSearchParamLastNEntity.java index 70f8996089a..c56753063ee 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/entity/ObservationIndexedSearchParamLastNEntity.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/lastn/entity/ObservationIndexedSearchParamLastNEntity.java @@ -17,7 +17,7 @@ public class ObservationIndexedSearchParamLastNEntity { private Long myId; @Field(name = "subject", analyze = Analyze.NO) - @Column(name = "LASTN_SUBJECT_ID", nullable = false) + @Column(name = "LASTN_SUBJECT_ID", nullable = true) private String mySubject; @ManyToOne(fetch = FetchType.LAZY) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoObservationR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoObservationR4.java index 18aa3098b2f..cc3d220c82c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoObservationR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoObservationR4.java @@ -22,33 +22,20 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoObservation; -import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.jpa.dao.lastn.ObservationLastNIndexPersistR4Svc; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; -import ca.uhn.fhir.jpa.model.entity.ResourceLink; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; -import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.api.CacheControlDirective; import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.StringAndListParam; -import ca.uhn.fhir.rest.param.StringParam; 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 org.hl7.fhir.r4.model.Observation; -import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Reference; import org.springframework.beans.factory.annotation.Autowired; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.Collection; -import java.util.Collections; import java.util.Date; public class FhirResourceDaoObservationR4 extends BaseHapiFhirResourceDao implements IFhirResourceDaoObservation { @@ -75,18 +62,9 @@ public class FhirResourceDaoObservationR4 extends BaseHapiFhirResourceDao myResourceLinks = retVal.getResourceLinks(); - Long subjectID = null; - for (ResourceLink resourceLink : myResourceLinks) { - if(resourceLink.getSourcePath().equals("Observation.subject")) { - subjectID = resourceLink.getTargetResourcePid(); - } - } - if (subjectID != null) { - myObservationLastNIndexPersistR4Svc.indexObservation(observation, subjectID.toString()); - } else { - myObservationLastNIndexPersistR4Svc.indexObservation(observation); - } + Reference subjectReference = observation.getSubject(); + String subjectID = subjectReference.getIdElement().getValue(); + myObservationLastNIndexPersistR4Svc.indexObservation(observation, subjectID); } return retVal; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoObservationR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoObservationR5.java index 665f425ea20..d39d69f7621 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoObservationR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoObservationR5.java @@ -24,7 +24,6 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoObservation; import ca.uhn.fhir.jpa.dao.lastn.ObservationLastNIndexPersistR5Svc; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; -import ca.uhn.fhir.jpa.model.entity.ResourceLink; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum; @@ -40,12 +39,11 @@ import ca.uhn.fhir.rest.param.StringParam; 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 org.hl7.fhir.r5.model.Reference; import org.hl7.fhir.r5.model.Observation; import org.springframework.beans.factory.annotation.Autowired; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -93,20 +91,12 @@ public class FhirResourceDaoObservationR5 extends BaseHapiFhirResourceDao myResourceLinks = retVal.getResourceLinks(); - Long subjectID = null; - for (ResourceLink resourceLink : myResourceLinks) { - if(resourceLink.getSourcePath().equals("Observation.subject")) { - subjectID = resourceLink.getTargetResourcePid(); - } - } - if (subjectID != null) { - myObservationLastNIndexPersistR5Svc.indexObservation(observation, subjectID.toString()); - } else { - myObservationLastNIndexPersistR5Svc.indexObservation(observation); - } + Reference subjectReference = observation.getSubject(); + String subjectID = subjectReference.getIdElement().getValue(); + myObservationLastNIndexPersistR5Svc.indexObservation(observation, subjectID); } + return retVal; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderObservationDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderObservationDstu2.java index ff9956b2c32..89a68df138a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderObservationDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderObservationDstu2.java @@ -9,6 +9,7 @@ import ca.uhn.fhir.model.dstu2.resource.Observation; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SearchTotalModeEnum; +import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -73,10 +74,6 @@ public class BaseJpaResourceProviderObservationDstu2 extends JpaResourceProvider @OperationParam(name="date") DateRangeParam theDate, - @Description(shortDefinition="The maximum number of observations to return for each each observation code") - @OperationParam(name="max", max=1, min=0) - NumberParam theMax, - @Description(shortDefinition="The subject that the observation is about (if patient)") @OperationParam(name="patient") ReferenceAndListParam thePatient, @@ -127,19 +124,27 @@ public class BaseJpaResourceProviderObservationDstu2 extends JpaResourceProvider paramMap.add("category", theCategory); paramMap.add("code", theCode); paramMap.add("date", theDate); - paramMap.add("max", theMax); paramMap.add("patient", thePatient); paramMap.add("subject", theSubject); paramMap.setRevIncludes(theRevIncludes); paramMap.setLastUpdated(theLastUpdated); paramMap.setIncludes(theIncludes); paramMap.setLastN(true); + if (theSort == null) { + SortSpec effectiveDtm = new SortSpec("date").setOrder(SortOrderEnum.DESC); + SortSpec observationCode = new SortSpec("code").setOrder(SortOrderEnum.ASC).setChain(effectiveDtm); + if (thePatient != null && theSubject == null) { + theSort = new SortSpec("patient").setChain(observationCode); + } else { + theSort = new SortSpec("subject").setChain(observationCode); + } + } paramMap.setSort(theSort); paramMap.setCount(theCount); paramMap.setSummaryMode(theSummaryMode); paramMap.setSearchTotalMode(theSearchTotalMode); - return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse); + return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse); } finally { endRequest(theServletRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderObservationDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderObservationDstu3.java index eb852776af4..2e2e60e1c89 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderObservationDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderObservationDstu3.java @@ -8,6 +8,7 @@ import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SearchTotalModeEnum; +import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -73,10 +74,6 @@ public class BaseJpaResourceProviderObservationDstu3 extends JpaResourceProvider @OperationParam(name="date") DateRangeParam theDate, - @Description(shortDefinition="The maximum number of observations to return for each each observation code") - @OperationParam(name="max", max=1, min=0) - NumberParam theMax, - @Description(shortDefinition="The subject that the observation is about (if patient)") @OperationParam(name="patient") ReferenceAndListParam thePatient, @@ -127,19 +124,27 @@ public class BaseJpaResourceProviderObservationDstu3 extends JpaResourceProvider paramMap.add("category", theCategory); paramMap.add("code", theCode); paramMap.add("date", theDate); - paramMap.add("max", theMax); paramMap.add("patient", thePatient); paramMap.add("subject", theSubject); paramMap.setRevIncludes(theRevIncludes); paramMap.setLastUpdated(theLastUpdated); paramMap.setIncludes(theIncludes); paramMap.setLastN(true); + if (theSort == null) { + SortSpec effectiveDtm = new SortSpec("date").setOrder(SortOrderEnum.DESC); + SortSpec observationCode = new SortSpec("code").setOrder(SortOrderEnum.ASC).setChain(effectiveDtm); + if (thePatient != null && theSubject == null) { + theSort = new SortSpec("patient").setChain(observationCode); + } else { + theSort = new SortSpec("subject").setChain(observationCode); + } + } paramMap.setSort(theSort); paramMap.setCount(theCount); paramMap.setSummaryMode(theSummaryMode); paramMap.setSearchTotalMode(theSearchTotalMode); - return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse); + return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse); } finally { endRequest(theServletRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderObservationR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderObservationR4.java index d8fb025c1be..c1c7b5dd430 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderObservationR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderObservationR4.java @@ -8,6 +8,7 @@ import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SearchTotalModeEnum; +import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -73,10 +74,6 @@ public class BaseJpaResourceProviderObservationR4 extends JpaResourceProviderR4< @OperationParam(name="date") DateRangeParam theDate, -// @Description(shortDefinition="The maximum number of observations to return for each each observation code") -// @OperationParam(name="max", max=1, min=0) -// NumberParam theMax, - @Description(shortDefinition="The subject that the observation is about (if patient)") @OperationParam(name="patient") ReferenceAndListParam thePatient, @@ -127,13 +124,21 @@ public class BaseJpaResourceProviderObservationR4 extends JpaResourceProviderR4< paramMap.add("category", theCategory); paramMap.add("code", theCode); paramMap.add("date", theDate); -// paramMap.add("max", theMax); paramMap.add("patient", thePatient); paramMap.add("subject", theSubject); paramMap.setRevIncludes(theRevIncludes); paramMap.setLastUpdated(theLastUpdated); paramMap.setIncludes(theIncludes); paramMap.setLastN(true); + if (theSort == null) { + SortSpec effectiveDtm = new SortSpec("date").setOrder(SortOrderEnum.DESC); + SortSpec observationCode = new SortSpec("code").setOrder(SortOrderEnum.ASC).setChain(effectiveDtm); + if (thePatient != null && theSubject == null) { + theSort = new SortSpec("patient").setChain(observationCode); + } else { + theSort = new SortSpec("subject").setChain(observationCode); + } + } paramMap.setSort(theSort); paramMap.setCount(theCount); paramMap.setSummaryMode(theSummaryMode); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderObservationR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderObservationR5.java index 85a4dcd7c2a..68bf078f778 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderObservationR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderObservationR5.java @@ -8,6 +8,7 @@ import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.SearchTotalModeEnum; +import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -73,10 +74,6 @@ public class BaseJpaResourceProviderObservationR5 extends JpaResourceProviderR5< @OperationParam(name="date") DateRangeParam theDate, - @Description(shortDefinition="The maximum number of observations to return for each each observation code") - @OperationParam(name="max", max=1, min=0) - NumberParam theMax, - @Description(shortDefinition="The subject that the observation is about (if patient)") @OperationParam(name="patient") ReferenceAndListParam thePatient, @@ -127,19 +124,27 @@ public class BaseJpaResourceProviderObservationR5 extends JpaResourceProviderR5< paramMap.add("category", theCategory); paramMap.add("code", theCode); paramMap.add("date", theDate); - paramMap.add("max", theMax); paramMap.add("patient", thePatient); paramMap.add("subject", theSubject); paramMap.setRevIncludes(theRevIncludes); paramMap.setLastUpdated(theLastUpdated); paramMap.setIncludes(theIncludes); paramMap.setLastN(true); + if (theSort == null) { + SortSpec effectiveDtm = new SortSpec("date").setOrder(SortOrderEnum.DESC); + SortSpec observationCode = new SortSpec("code").setOrder(SortOrderEnum.ASC).setChain(effectiveDtm); + if (thePatient != null && theSubject == null) { + theSort = new SortSpec("patient").setChain(observationCode); + } else { + theSort = new SortSpec("subject").setChain(observationCode); + } + } paramMap.setSort(theSort); paramMap.setCount(theCount); paramMap.setSummaryMode(theSummaryMode); paramMap.setSearchTotalMode(theSearchTotalMode); - return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse); + return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse); } finally { endRequest(theServletRequest); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java index fa8061c5212..ef5f2c4b0cd 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/lastn/ElasticsearchSvcImpl.java @@ -415,11 +415,7 @@ public class ElasticsearchSvcImpl implements IElasticsearchSvc { if (nextOr instanceof ReferenceParam) { ReferenceParam ref = (ReferenceParam) nextOr; if (isBlank(ref.getChain())) { - if (ref.getResourceType() != null) { - referenceList.add(ref.getResourceType() + "/" + ref.getValue()); - } else { - referenceList.add(ref.getValue()); - } + referenceList.add(ref.getValue()); } } else { throw new IllegalArgumentException("Invalid token type (expecting ReferenceParam): " + nextOr.getClass()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/IntegratedObservationIndexedSearchParamLastNTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/IntegratedObservationIndexedSearchParamLastNTest.java index 9413e5ae26d..1ba180c5ff7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/IntegratedObservationIndexedSearchParamLastNTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/IntegratedObservationIndexedSearchParamLastNTest.java @@ -124,7 +124,7 @@ public class IntegratedObservationIndexedSearchParamLastNTest { // codeableConceptField.addCoding(new Coding("http://mysecondaltcodes.org/fhir/observation-code", "test-second-alt-code", "test-second-alt-code display")); myObservation.setCode(codeableConceptField); - myObservationLastNIndexPersistR4Svc.indexObservation(myObservation); + myObservationLastNIndexPersistR4Svc.indexObservation(myObservation, "4567"); SearchParameterMap searchParameterMap = new SearchParameterMap(); ReferenceParam subjectParam = new ReferenceParam("Patient", "", SUBJECTID); @@ -213,7 +213,7 @@ public class IntegratedObservationIndexedSearchParamLastNTest { Date effectiveDtm = observationDate.getTime(); observation.setEffective(new DateTimeType(effectiveDtm)); - myObservationLastNIndexPersistR4Svc.indexObservation(observation); + myObservationLastNIndexPersistR4Svc.indexObservation(observation, String.valueOf(patientCount)); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/PersistObservationIndexedSearchParamLastNTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/PersistObservationIndexedSearchParamLastNTest.java index 1ea31e450bb..d117a41de72 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/PersistObservationIndexedSearchParamLastNTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/lastn/PersistObservationIndexedSearchParamLastNTest.java @@ -94,12 +94,12 @@ public class PersistObservationIndexedSearchParamLastNTest { codeableConceptField.addCoding(new Coding("http://mysecondaltcodes.org/fhir/observation-code", "test-second-alt-code", "test-second-alt-code display")); myObservation.setCode(codeableConceptField); - myObservationLastNIndexPersistR4Svc.indexObservation(myObservation); + myObservationLastNIndexPersistR4Svc.indexObservation(myObservation, "4567"); List persistedObservationEntities = myResourceIndexedObservationLastNDao.findAll(); assertEquals(1, persistedObservationEntities.size()); ObservationIndexedSearchParamLastNEntity persistedObservationEntity = persistedObservationEntities.get(0); - assertEquals("Patient/"+subjectId.getReference(), persistedObservationEntity.getSubject()); + assertEquals(subjectId.getReference(), persistedObservationEntity.getSubject()); assertEquals(resourcePID, persistedObservationEntity.getIdentifier()); assertEquals(effectiveDtm, persistedObservationEntity.getEffectiveDtm()); @@ -171,7 +171,7 @@ public class PersistObservationIndexedSearchParamLastNTest { Date effectiveDtm = observationDate.getTime(); observation.setEffective(new DateTimeType(effectiveDtm)); - myObservationLastNIndexPersistR4Svc.indexObservation(observation); + myObservationLastNIndexPersistR4Svc.indexObservation(observation, subjectId); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsTest.java index 58d69592b8d..50da9dbe3da 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsTest.java @@ -260,7 +260,7 @@ public class LastNElasticsearchSvcMultipleObservationsTest { for (int patientCount = 0; patientCount < 10 ; patientCount++) { - String subject = "Patient/"+patientCount; + String subject = String.valueOf(patientCount); for ( int entryCount = 0; entryCount < 10 ; entryCount++ ) { diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceLink.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceLink.java index 44438c28626..39ecf5f5a8d 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceLink.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceLink.java @@ -162,6 +162,10 @@ public class ResourceLink extends BaseResourceIndex { myTargetResourceUrl = theTargetResourceUrl.getValue(); } + public String getTargetResourceUrl() { + return myTargetResourceUrl; + } + public void setTargetResourceUrlCanonical(String theTargetResourceUrl) { Validate.notBlank(theTargetResourceUrl);