Consolidate changes to Command Line Tool and add/improve tests.

This commit is contained in:
ianmarshall 2020-04-10 16:58:00 -04:00
parent 83e673e725
commit e64d67f429
16 changed files with 68 additions and 108 deletions

View File

@ -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<Obs
if(thePerformIndexing) {
// Update indexes here for LastN operation.
Observation observation = (Observation)theResource;
Collection<ResourceLink> 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;

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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<Observation> implements IFhirResourceDaoObservation<Observation> {
@ -75,18 +62,9 @@ public class FhirResourceDaoObservationR4 extends BaseHapiFhirResourceDao<Observ
if(thePerformIndexing) {
// Update indexes here for LastN operation.
Observation observation = (Observation)theResource;
Collection<ResourceLink> 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;

View File

@ -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<Observ
if(thePerformIndexing) {
// Update indexes here for LastN operation.
Observation observation = (Observation)theResource;
Collection<ResourceLink> 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;
}

View File

@ -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<Observation>) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
return ((IFhirResourceDaoObservation) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
} finally {
endRequest(theServletRequest);
}

View File

@ -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<Observation>) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
return ((IFhirResourceDaoObservation<org.hl7.fhir.dstu3.model.Observation>) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
} finally {
endRequest(theServletRequest);
}

View File

@ -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);

View File

@ -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<Observation>) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
return ((IFhirResourceDaoObservation<org.hl7.fhir.r5.model.Observation>) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
} finally {
endRequest(theServletRequest);
}

View File

@ -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());

View File

@ -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));
}

View File

@ -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<ObservationIndexedSearchParamLastNEntity> 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);
}

View File

@ -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++ ) {

View File

@ -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);