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 055063acdc9..664ee30f149 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 @@ -146,6 +146,7 @@ public abstract class BaseHapiFhirDao implements IDao { */ static final Map> RESOURCE_META_PARAMS; public static final String UCUM_NS = "http://unitsofmeasure.org"; + private static final Set EXCLUDE_ELEMENTS_IN_ENCODED; static { Map> resourceMetaParams = new HashMap>(); @@ -162,6 +163,11 @@ public abstract class BaseHapiFhirDao implements IDao { resourceMetaAndParams.put(Constants.PARAM_SECURITY, TokenAndListParam.class); RESOURCE_META_PARAMS = Collections.unmodifiableMap(resourceMetaParams); RESOURCE_META_AND_PARAMS = Collections.unmodifiableMap(resourceMetaAndParams); + + HashSet excludeElementsInEncoded = new HashSet(); + excludeElementsInEncoded.add("*.id"); + excludeElementsInEncoded.add("*.meta"); + EXCLUDE_ELEMENTS_IN_ENCODED = Collections.unmodifiableSet(excludeElementsInEncoded); } @Autowired(required = true) @@ -833,9 +839,13 @@ public abstract class BaseHapiFhirDao implements IDao { } } } - - String encoded = myConfig.getResourceEncoding().newParser(myContext).encodeResourceToString(theResource); + ResourceEncodingEnum encoding = myConfig.getResourceEncoding(); + + IParser parser = encoding.newParser(myContext); + parser.setDontEncodeElements(EXCLUDE_ELEMENTS_IN_ENCODED); + String encoded = parser.encodeResourceToString(theResource); + theEntity.setEncoding(encoding); theEntity.setFhirVersion(myContext.getVersion().getVersion()); switch (encoding) { @@ -1057,7 +1067,7 @@ public abstract class BaseHapiFhirDao implements IDao { } IFhirResourceDao dao = getDao(theResourceType); - Set ids = dao.searchForIdsWithAndOr(paramMap); + Set ids = dao.searchForIds(paramMap); return ids; } @@ -1582,12 +1592,6 @@ public abstract class BaseHapiFhirDao implements IDao { return updateEntity(theResource, entity, theDeletedTimestampOrNull, true, true, theUpdateTime); } - private void updateSearchParamPresent(Map presentSearchParams, Set params) { - for (BaseResourceIndexedSearchParam nextSearchParam : params) { - presentSearchParams.put(nextSearchParam.getParamName(), Boolean.TRUE); - } - } - private void validateChildReferences(IBase theElement, String thePath) { if (theElement == null) { return; 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 c6120c51e0f..308f2f85bbe 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 @@ -883,22 +883,10 @@ public abstract class BaseHapiFhirResourceDao extends B } - @Override - public Set searchForIds(Map theParams) { - SearchParameterMap map = new SearchParameterMap(); - for (Entry nextEntry : theParams.entrySet()) { - map.add(nextEntry.getKey(), (nextEntry.getValue())); - } - return searchForIdsWithAndOr(map); - } + @Override - public Set searchForIds(String theParameterName, IQueryParameterType theValue) { - return searchForIds(Collections.singletonMap(theParameterName, theValue)); - } - - @Override - public Set searchForIdsWithAndOr(SearchParameterMap theParams) { + public Set searchForIds(SearchParameterMap theParams) { SearchBuilder builder = newSearchBuilder(); builder.setType(getResourceType(), getResourceName()); @@ -1090,6 +1078,8 @@ public abstract class BaseHapiFhirResourceDao extends B "Invalid resource ID[" + entity.getIdDt().toUnqualifiedVersionless() + "] of type[" + entity.getResourceType() + "] - Does not match expected [" + getResourceName() + "]"); } +// entity.get + // Notify interceptors ActionRequestDetails requestDetails = null; if (theRequestDetails != null) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu2.java index 9905cd282dc..ce8550634dc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoValueSetDstu2.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.jpa.dao; * 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 + * 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, @@ -56,27 +56,44 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 implements IFhirResourceDaoValueSet, IFhirResourceDaoCodeSystem { +public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 + implements IFhirResourceDaoValueSet, IFhirResourceDaoCodeSystem { + + private DefaultProfileValidationSupport myDefaultProfileValidationSupport; @Autowired private IJpaValidationSupportDstu2 myJpaValidationSupport; - - private ValidationSupportChain myValidationSupport; - + @Autowired @Qualifier("myFhirContextDstu2Hl7Org") private FhirContext myRiCtx; - private DefaultProfileValidationSupport myDefaultProfileValidationSupport; + private ValidationSupportChain myValidationSupport; - @Override - @PostConstruct - public void postConstruct() { - super.postConstruct(); - myDefaultProfileValidationSupport = new DefaultProfileValidationSupport(); - myValidationSupport = new ValidationSupportChain(myDefaultProfileValidationSupport, myJpaValidationSupport); + private void addCompose(String theFilter, ValueSet theValueSetToPopulate, ValueSet theSourceValueSet, CodeSystemConcept theConcept) { + if (isBlank(theFilter)) { + addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay()); + } else { + String filter = theFilter.toLowerCase(); + if (theConcept.getDisplay().toLowerCase().contains(filter) || theConcept.getCode().toLowerCase().contains(filter)) { + addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay()); + } + } + for (CodeSystemConcept nextChild : theConcept.getConcept()) { + addCompose(theFilter, theValueSetToPopulate, theSourceValueSet, nextChild); + } } - + + private void addCompose(ValueSet retVal, String theSystem, String theCode, String theDisplay) { + if (isBlank(theCode)) { + return; + } + ExpansionContains contains = retVal.getExpansion().addContains(); + contains.setSystem(theSystem); + contains.setCode(theCode); + contains.setDisplay(theDisplay); + } + @Override public ValueSet expand(IIdType theId, String theFilter, RequestDetails theRequestDetails) { ValueSet source = loadValueSetForExpansion(theId); @@ -84,51 +101,11 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 } - private ValueSet loadValueSetForExpansion(IIdType theId) { - if (theId.getValue().startsWith("http://hl7.org/fhir/")) { - org.hl7.fhir.instance.model.ValueSet valueSet = myValidationSupport.fetchResource(myRiCtx, org.hl7.fhir.instance.model.ValueSet.class, theId.getValue()); - if (valueSet != null) { - return getContext().newJsonParser().parseResource(ValueSet.class, myRiCtx.newJsonParser().encodeResourceToString(valueSet)); - } - } - BaseHasResource sourceEntity = readEntity(theId); - if (sourceEntity == null) { - throw new ResourceNotFoundException(theId); - } - ValueSet source = (ValueSet) toResource(sourceEntity, false); - return source; - } - - @Override - public ValueSet expandByIdentifier(String theUri, String theFilter) { - if (isBlank(theUri)) { - throw new InvalidRequestException("URI must not be blank or missing"); - } - ValueSet source; - - org.hl7.fhir.instance.model.ValueSet defaultValueSet = myDefaultProfileValidationSupport.fetchResource(myRiCtx, org.hl7.fhir.instance.model.ValueSet.class, theUri); - if (defaultValueSet != null) { - source = getContext().newJsonParser().parseResource(ValueSet.class, myRiCtx.newJsonParser().encodeResourceToString(defaultValueSet)); - } else { - SearchParameterMap params = new SearchParameterMap(); - params.setLoadSynchronousUpTo(1); - params.add(ValueSet.SP_URL, new UriParam(theUri)); - IBundleProvider ids = search(params); - if (ids.size() == 0) { - throw new InvalidRequestException("Unknown ValueSet URI: " + theUri); - } - source = (ValueSet) ids.getResources(0, 1).get(0); - } - - return expand(source, theFilter); - - } - @Override public ValueSet expand(ValueSet source, String theFilter) { ValueSet retVal = new ValueSet(); retVal.setDate(DateTimeDt.withCurrentTime()); - + /* * Add composed concepts */ @@ -157,32 +134,145 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 return retVal; } - private void addCompose(String theFilter, ValueSet theValueSetToPopulate, ValueSet theSourceValueSet, CodeSystemConcept theConcept) { - if (isBlank(theFilter)) { - addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay()); - } else { - String filter = theFilter.toLowerCase(); - if (theConcept.getDisplay().toLowerCase().contains(filter) || theConcept.getCode().toLowerCase().contains(filter)) { - addCompose(theValueSetToPopulate, theSourceValueSet.getCodeSystem().getSystem(), theConcept.getCode(), theConcept.getDisplay()); - } + @Override + public ValueSet expandByIdentifier(String theUri, String theFilter) { + if (isBlank(theUri)) { + throw new InvalidRequestException("URI must not be blank or missing"); } - for (CodeSystemConcept nextChild : theConcept.getConcept()) { - addCompose(theFilter, theValueSetToPopulate, theSourceValueSet, nextChild); - } - } + ValueSet source; - private void addCompose(ValueSet retVal, String theSystem, String theCode, String theDisplay) { - if (isBlank(theCode)) { - return; + org.hl7.fhir.instance.model.ValueSet defaultValueSet = myDefaultProfileValidationSupport.fetchResource(myRiCtx, org.hl7.fhir.instance.model.ValueSet.class, theUri); + if (defaultValueSet != null) { + source = getContext().newJsonParser().parseResource(ValueSet.class, myRiCtx.newJsonParser().encodeResourceToString(defaultValueSet)); + } else { + SearchParameterMap params = new SearchParameterMap(); + params.setLoadSynchronousUpTo(1); + params.add(ValueSet.SP_URL, new UriParam(theUri)); + IBundleProvider ids = search(params); + if (ids.size() == 0) { + throw new InvalidRequestException("Unknown ValueSet URI: " + theUri); + } + source = (ValueSet) ids.getResources(0, 1).get(0); } - ExpansionContains contains = retVal.getExpansion().addContains(); - contains.setSystem(theSystem); - contains.setCode(theCode); - contains.setDisplay(theDisplay); + + return expand(source, theFilter); + } @Override - public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType theValueSetIdentifier, IIdType theId, IPrimitiveType theCode, IPrimitiveType theSystem, IPrimitiveType theDisplay, CodingDt theCoding, CodeableConceptDt theCodeableConcept, RequestDetails theRequestDetails) { + public List findCodeSystemIdsContainingSystemAndCode(String theCode, String theSystem) { + if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/")) { + return Collections.singletonList((IIdType) new IdDt(theSystem)); + } + + List valueSetIds; + Set ids = searchForIds(new SearchParameterMap(ValueSet.SP_CODE, new TokenParam(theSystem, theCode))); + valueSetIds = new ArrayList(); + for (Long next : ids) { + valueSetIds.add(new IdDt("ValueSet", next)); + } + return valueSetIds; + } + + private ValueSet loadValueSetForExpansion(IIdType theId) { + if (theId.getValue().startsWith("http://hl7.org/fhir/")) { + org.hl7.fhir.instance.model.ValueSet valueSet = myValidationSupport.fetchResource(myRiCtx, org.hl7.fhir.instance.model.ValueSet.class, theId.getValue()); + if (valueSet != null) { + return getContext().newJsonParser().parseResource(ValueSet.class, myRiCtx.newJsonParser().encodeResourceToString(valueSet)); + } + } + BaseHasResource sourceEntity = readEntity(theId); + if (sourceEntity == null) { + throw new ResourceNotFoundException(theId); + } + ValueSet source = (ValueSet) toResource(sourceEntity, false); + return source; + } + + private LookupCodeResult lookup(List theContains, String theSystem, String theCode) { + for (ExpansionContains nextCode : theContains) { + + String system = nextCode.getSystem(); + String code = nextCode.getCode(); + if (theSystem.equals(system) && theCode.equals(code)) { + LookupCodeResult retVal = new LookupCodeResult(); + retVal.setSearchedForCode(code); + retVal.setSearchedForSystem(system); + retVal.setFound(true); + if (nextCode.getAbstract() != null) { + retVal.setCodeIsAbstract(nextCode.getAbstract().booleanValue()); + } + retVal.setCodeDisplay(nextCode.getDisplay()); + retVal.setCodeSystemVersion(nextCode.getVersion()); + retVal.setCodeSystemDisplayName("Unknown"); // TODO: implement + return retVal; + } + + } + + return null; + } + + @Override + public 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; + + if (!haveCoding && !(haveSystem && haveCode)) { + throw new InvalidRequestException("No code, coding, or codeableConcept provided to validate"); + } + if (!multiXor(haveCoding, (haveSystem && haveCode)) || (haveSystem != haveCode)) { + throw new InvalidRequestException("$lookup can only validate (system AND code) OR (coding.system AND coding.code)"); + } + + String code; + String system; + if (haveCoding) { + code = theCoding.getCode(); + system = theCoding.getSystem(); + } else { + code = theCode.getValue(); + system = theSystem.getValue(); + } + + List valueSetIds = findCodeSystemIdsContainingSystemAndCode(code, system); + for (IIdType nextId : valueSetIds) { + ValueSet expansion = expand(nextId, null, theRequestDetails); + List contains = expansion.getExpansion().getContains(); + LookupCodeResult result = lookup(contains, system, code); + if (result != null) { + return result; + } + } + + LookupCodeResult retVal = new LookupCodeResult(); + retVal.setFound(false); + retVal.setSearchedForCode(code); + retVal.setSearchedForSystem(system); + return retVal; + } + + @Override + @PostConstruct + public void postConstruct() { + super.postConstruct(); + myDefaultProfileValidationSupport = new DefaultProfileValidationSupport(); + myValidationSupport = new ValidationSupportChain(myDefaultProfileValidationSupport, myJpaValidationSupport); + } + + @Override + public void purgeCaches() { + // nothing + } + + private String toStringOrNull(IPrimitiveType thePrimitive) { + return thePrimitive != null ? thePrimitive.getValue() : null; + } + + @Override + public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(IPrimitiveType theValueSetIdentifier, IIdType theId, IPrimitiveType theCode, + IPrimitiveType theSystem, IPrimitiveType theDisplay, CodingDt theCoding, CodeableConceptDt theCodeableConcept, RequestDetails theRequestDetails) { List valueSetIds; boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0; @@ -200,7 +290,7 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 if (theId != null) { valueSetIds = Collections.singletonList(theId); } else if (haveIdentifierParam) { - Set ids = searchForIds(ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue())); + Set ids = searchForIds(new SearchParameterMap(ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue()))); valueSetIds = new ArrayList(); for (Long next : ids) { valueSetIds.add(new IdDt("ValueSet", next)); @@ -231,35 +321,6 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 return new ValidateCodeResult(false, "Code not found", null); } - @Override - public List findCodeSystemIdsContainingSystemAndCode(String theCode, String theSystem) { - if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/")) { - return Collections.singletonList((IIdType)new IdDt(theSystem)); - } - - List valueSetIds; - Set ids = searchForIds(ValueSet.SP_CODE, new TokenParam(theSystem, theCode)); - valueSetIds = new ArrayList(); - for (Long next : ids) { - valueSetIds.add(new IdDt("ValueSet", next)); - } - return valueSetIds; - } - - private static boolean multiXor(boolean... theValues) { - int count = 0; - for (int i = 0; i < theValues.length; i++) { - if (theValues[i]) { - count++; - } - } - return count == 1; - } - - private String toStringOrNull(IPrimitiveType thePrimitive) { - return thePrimitive != null ? thePrimitive.getValue() : null; - } - private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains(List contains, String theSystem, String theCode, CodingDt theCoding, CodeableConceptDt theCodeableConcept) { for (ExpansionContains nextCode : contains) { @@ -292,74 +353,14 @@ public class FhirResourceDaoValueSetDstu2 extends FhirResourceDaoDstu2 return null; } - @Override - public 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; - - if (!haveCoding && !(haveSystem && haveCode)) { - throw new InvalidRequestException("No code, coding, or codeableConcept provided to validate"); - } - if (!multiXor(haveCoding, (haveSystem && haveCode)) || (haveSystem != haveCode)) { - throw new InvalidRequestException("$lookup can only validate (system AND code) OR (coding.system AND coding.code)"); - } - - String code; - String system; - if (haveCoding) { - code = theCoding.getCode(); - system = theCoding.getSystem(); - } else { - code = theCode.getValue(); - system = theSystem.getValue(); - } - - List valueSetIds = findCodeSystemIdsContainingSystemAndCode(code, system); - for (IIdType nextId : valueSetIds) { - ValueSet expansion = expand(nextId, null, theRequestDetails); - List contains = expansion.getExpansion().getContains(); - LookupCodeResult result = lookup(contains, system, code); - if (result != null) { - return result; + private static boolean multiXor(boolean... theValues) { + int count = 0; + for (int i = 0; i < theValues.length; i++) { + if (theValues[i]) { + count++; } } - - LookupCodeResult retVal = new LookupCodeResult(); - retVal.setFound(false); - retVal.setSearchedForCode(code); - retVal.setSearchedForSystem(system); - return retVal; + return count == 1; } - private LookupCodeResult lookup(List theContains, String theSystem, String theCode) { - for (ExpansionContains nextCode : theContains) { - - String system = nextCode.getSystem(); - String code = nextCode.getCode(); - if (theSystem.equals(system) && theCode.equals(code)) { - LookupCodeResult retVal = new LookupCodeResult(); - retVal.setSearchedForCode(code); - retVal.setSearchedForSystem(system); - retVal.setFound(true); - if (nextCode.getAbstract() != null) { - retVal.setCodeIsAbstract(nextCode.getAbstract().booleanValue()); - } - retVal.setCodeDisplay(nextCode.getDisplay()); - retVal.setCodeSystemVersion(nextCode.getVersion()); - retVal.setCodeSystemDisplayName("Unknown"); // TODO: implement - return retVal; - } - - } - - return null; - } - - @Override - public void purgeCaches() { - // nothing - } - - } 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 81da4189ca4..165543ee316 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 @@ -178,11 +178,7 @@ public interface IFhirResourceDao extends IDao { IBundleProvider search(SearchParameterMap theParams, RequestDetails theRequestDetails); - Set searchForIds(Map theParams); - - Set searchForIds(String theParameterName, IQueryParameterType theValue); - - Set searchForIdsWithAndOr(SearchParameterMap theParams); + Set searchForIds(SearchParameterMap theParams); /** * Takes a map of incoming raw search parameters and translates/parses them into diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java index 1bea0640a21..aff365a09e6 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java @@ -41,6 +41,7 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoCodeSystem; +import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao; import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; @@ -65,7 +66,7 @@ public class FhirResourceDaoCodeSystemDstu3 extends FhirResourceDaoDstu3 findCodeSystemIdsContainingSystemAndCode(String theCode, String theSystem) { List valueSetIds; - Set ids = searchForIds(CodeSystem.SP_CODE, new TokenParam(theSystem, theCode)); + Set ids = searchForIds(new SearchParameterMap(CodeSystem.SP_CODE, new TokenParam(theSystem, theCode))); valueSetIds = new ArrayList(); for (Long next : ids) { valueSetIds.add(new IdType("CodeSystem", next)); 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 0aba1f66eb2..f1be50df7bf 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 @@ -1590,7 +1590,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { QuantityParam param; Set found; param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, null); - found = myObservationDao.searchForIds("value-quantity", param); + found = myObservationDao.searchForIds(new SearchParameterMap("value-quantity", param)); int initialSize = found.size(); Observation o = new Observation(); @@ -1601,19 +1601,19 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { myObservationDao.create(o, mySrd); param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, null); - found = myObservationDao.searchForIds("value-quantity", param); + found = myObservationDao.searchForIds(new SearchParameterMap("value-quantity", param)); assertEquals(1 + initialSize, found.size()); param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), null, methodName + "units"); - found = myObservationDao.searchForIds("value-quantity", param); + found = myObservationDao.searchForIds(new SearchParameterMap("value-quantity", param)); assertEquals(1, found.size()); param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), "urn:bar:" + methodName, null); - found = myObservationDao.searchForIds("value-quantity", param); + found = myObservationDao.searchForIds(new SearchParameterMap("value-quantity", param)); assertEquals(1, found.size()); param = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, new BigDecimal("10"), "urn:bar:" + methodName, methodName + "units"); - found = myObservationDao.searchForIds("value-quantity", param); + found = myObservationDao.searchForIds(new SearchParameterMap("value-quantity", param)); assertEquals(1, found.size()); } 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 102bb1c5cb0..137791e5846 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 @@ -237,7 +237,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertThat(toUnqualifiedVersionlessIdValues(found), hasItem(id2.getValue())); } { - Set found = myObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2016-01-02")); + Set found = myObservationDao.searchForIds(new SearchParameterMap(Observation.SP_DATE, new DateParam(">2016-01-02"))); assertThat(found, not(hasItem(id2.getIdPartAsLong()))); } } @@ -1624,13 +1624,13 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { "}\n"; //@formatter:on - Set val = myOrganizationDao.searchForIds("name", new StringParam("P")); + Set val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); int initial = val.size(); Organization org = myFhirCtx.newJsonParser().parseResource(Organization.class, inputStr); myOrganizationDao.create(org, mySrd); - val = myOrganizationDao.searchForIds("name", new StringParam("P")); + val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); assertEquals(initial + 1, val.size()); } @@ -2783,19 +2783,19 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertThat(str.length(), greaterThan(ResourceIndexedSearchParamString.MAX_LENGTH)); - Set val = myOrganizationDao.searchForIds("name", new StringParam("P")); + Set val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); int initial = val.size(); myOrganizationDao.create(org, mySrd); - val = myOrganizationDao.searchForIds("name", new StringParam("P")); + val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); assertEquals(initial + 0, val.size()); - val = myOrganizationDao.searchForIds("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH))); + val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH)))); assertEquals(initial + 1, val.size()); try { - myOrganizationDao.searchForIds("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH + 1))); + myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH + 1)))); fail(); } catch (InvalidRequestException e) { // ok @@ -2931,23 +2931,23 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String subStr1 = longStr1.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH); String subStr2 = longStr2.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH); - Set val = myOrganizationDao.searchForIds("type", new IdentifierDt(subStr1, subStr2)); + Set val = myOrganizationDao.searchForIds(new SearchParameterMap("type", new IdentifierDt(subStr1, subStr2))); int initial = val.size(); myOrganizationDao.create(org, mySrd); - val = myOrganizationDao.searchForIds("type", new IdentifierDt(subStr1, subStr2)); + val = myOrganizationDao.searchForIds(new SearchParameterMap("type", new IdentifierDt(subStr1, subStr2))); assertEquals(initial + 1, val.size()); try { - myOrganizationDao.searchForIds("type", new IdentifierDt(longStr1, subStr2)); + myOrganizationDao.searchForIds(new SearchParameterMap("type", new IdentifierDt(longStr1, subStr2))); fail(); } catch (InvalidRequestException e) { // ok } try { - myOrganizationDao.searchForIds("type", new IdentifierDt(subStr1, longStr2)); + myOrganizationDao.searchForIds(new SearchParameterMap("type", new IdentifierDt(subStr1, longStr2))); fail(); } catch (InvalidRequestException e) { // ok 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 2578313cba4..8edeb5740e2 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 @@ -28,6 +28,7 @@ import org.junit.AfterClass; import org.junit.Test; import org.mockito.ArgumentCaptor; +import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.Tag; @@ -245,7 +246,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB"); myPatientDao.create(p2, mySrd).getId(); - Set ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA")); + Set ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA"))); assertEquals(1, ids.size()); assertThat(ids, contains(p1id.getIdPartAsLong())); @@ -254,10 +255,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { MethodOutcome update2 = myPatientDao.update(p1, mySrd); IIdType p1id2 = update2.getId(); - ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA")); + ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA"))); assertEquals(0, ids.size()); - ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2BBB")); + ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2BBB"))); assertEquals(2, ids.size()); // Make sure vreads work 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 f37ffd3f50a..7be6eec0b06 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 @@ -230,11 +230,11 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { IIdType id2 = myObservationDao.create(o2, mySrd).getId(); { - Set found = myObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2001-01-02")); + Set found = myObservationDao.searchForIds(new SearchParameterMap(Observation.SP_DATE, new DateParam(">2001-01-02"))); assertThat(found, hasItem(id2.getIdPartAsLong())); } { - Set found = myObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2016-01-02")); + Set found = myObservationDao.searchForIds(new SearchParameterMap(Observation.SP_DATE, new DateParam(">2016-01-02"))); assertThat(found, not(hasItem(id2.getIdPartAsLong()))); } } @@ -2016,13 +2016,13 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { "}\n"; //@formatter:on - Set val = myOrganizationDao.searchForIds("name", new StringParam("P")); + Set val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); int initial = val.size(); Organization org = myFhirCtx.newJsonParser().parseResource(Organization.class, inputStr); myOrganizationDao.create(org, mySrd); - val = myOrganizationDao.searchForIds("name", new StringParam("P")); + val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); assertEquals(initial + 1, val.size()); } @@ -3237,19 +3237,19 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertThat(str.length(), greaterThan(ResourceIndexedSearchParamString.MAX_LENGTH)); - Set val = myOrganizationDao.searchForIds("name", new StringParam("P")); + Set val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); int initial = val.size(); myOrganizationDao.create(org, mySrd); - val = myOrganizationDao.searchForIds("name", new StringParam("P")); + val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P"))); assertEquals(initial + 0, val.size()); - val = myOrganizationDao.searchForIds("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH))); + val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH)))); assertEquals(initial + 1, val.size()); try { - myOrganizationDao.searchForIds("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH + 1))); + myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH + 1)))); fail(); } catch (InvalidRequestException e) { // ok @@ -3416,23 +3416,23 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { String subStr1 = longStr1.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH); String subStr2 = longStr2.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH); - Set val = myOrganizationDao.searchForIds("type", new TokenParam(subStr1, subStr2)); + Set val = myOrganizationDao.searchForIds(new SearchParameterMap("type", new TokenParam(subStr1, subStr2))); int initial = val.size(); myOrganizationDao.create(org, mySrd); - val = myOrganizationDao.searchForIds("type", new TokenParam(subStr1, subStr2)); + val = myOrganizationDao.searchForIds(new SearchParameterMap("type", new TokenParam(subStr1, subStr2))); assertEquals(initial + 1, val.size()); try { - myOrganizationDao.searchForIds("type", new TokenParam(longStr1, subStr2)); + myOrganizationDao.searchForIds(new SearchParameterMap("type", new TokenParam(longStr1, subStr2))); fail(); } catch (InvalidRequestException e) { // ok } try { - myOrganizationDao.searchForIds("type", new TokenParam(subStr1, longStr2)); + myOrganizationDao.searchForIds(new SearchParameterMap("type", new TokenParam(subStr1, longStr2))); fail(); } catch (InvalidRequestException e) { // ok 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 dde3f202a45..a1a47ff21fb 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 @@ -37,6 +37,7 @@ import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; +import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; @@ -352,7 +353,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { p2.addName().setFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB"); myPatientDao.create(p2, mySrd).getId(); - Set ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA")); + Set ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA"))); assertEquals(1, ids.size()); assertThat(ids, contains(p1id.getIdPartAsLong())); @@ -361,10 +362,10 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { MethodOutcome update2 = myPatientDao.update(p1, mySrd); IIdType p1id2 = update2.getId(); - ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA")); + ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2AAA"))); assertEquals(0, ids.size()); - ids = myPatientDao.searchForIds(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2BBB")); + ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringParam("testUpdateMaintainsSearchParamsDstu2BBB"))); assertEquals(2, ids.size()); // Make sure vreads work