Revert "7_2 branch mergeback (#5922)" (#5927)

This reverts commit 125513a100.
This commit is contained in:
Tadgh 2024-05-12 16:04:43 -07:00 committed by GitHub
parent 125513a100
commit 3572d593c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
68 changed files with 470 additions and 1662 deletions

View File

@ -2387,19 +2387,13 @@ public enum Pointcut implements IPointcut {
* <li> * <li>
* ca.uhn.fhir.mdm.model.mdmevents.MdmMergeEvent - Contains information about the from and to resources. * ca.uhn.fhir.mdm.model.mdmevents.MdmMergeEvent - Contains information about the from and to resources.
* </li> * </li>
* <li>
* ca.uhn.fhir.mdm.model.mdmevents.MdmTransactionContext - Contains information about the Transaction context, e.g. merge or link.
* </li>
* </ul> * </ul>
* <p> * <p>
* Hooks should return <code>void</code>. * Hooks should return <code>void</code>.
* </p> * </p>
*/ */
MDM_POST_MERGE_GOLDEN_RESOURCES( MDM_POST_MERGE_GOLDEN_RESOURCES(
void.class, void.class, "ca.uhn.fhir.rest.api.server.RequestDetails", "ca.uhn.fhir.mdm.model.mdmevents.MdmMergeEvent"),
"ca.uhn.fhir.rest.api.server.RequestDetails",
"ca.uhn.fhir.mdm.model.mdmevents.MdmMergeEvent",
"ca.uhn.fhir.mdm.model.MdmTransactionContext"),
/** /**
* <b>MDM Link History Hook:</b> * <b>MDM Link History Hook:</b>

View File

@ -19,7 +19,6 @@
*/ */
package ca.uhn.fhir.cli; package ca.uhn.fhir.cli;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider; import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider;
@ -32,7 +31,6 @@ import ca.uhn.fhir.system.HapiSystemProperties;
import ca.uhn.fhir.util.AttachmentUtil; import ca.uhn.fhir.util.AttachmentUtil;
import ca.uhn.fhir.util.FileUtil; import ca.uhn.fhir.util.FileUtil;
import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.ParametersUtil;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
@ -267,7 +265,7 @@ public class UploadTerminologyCommand extends BaseRequestGeneratingCommand {
"Response:\n{}", myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response)); "Response:\n{}", myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
} }
protected void addFileToRequestBundle(IBaseParameters theInputParameters, String theFileName, byte[] theBytes) { private void addFileToRequestBundle(IBaseParameters theInputParameters, String theFileName, byte[] theBytes) {
byte[] bytes = theBytes; byte[] bytes = theBytes;
String fileName = theFileName; String fileName = theFileName;
@ -279,7 +277,7 @@ public class UploadTerminologyCommand extends BaseRequestGeneratingCommand {
FileUtil.formatFileSize(ourTransferSizeLimit)); FileUtil.formatFileSize(ourTransferSizeLimit));
try { try {
File tempFile = File.createTempFile("hapi-fhir-cli", "." + suffix); File tempFile = File.createTempFile("hapi-fhir-cli", suffix);
tempFile.deleteOnExit(); tempFile.deleteOnExit();
try (OutputStream fileOutputStream = new FileOutputStream(tempFile, false)) { try (OutputStream fileOutputStream = new FileOutputStream(tempFile, false)) {
fileOutputStream.write(bytes); fileOutputStream.write(bytes);
@ -365,9 +363,4 @@ public class UploadTerminologyCommand extends BaseRequestGeneratingCommand {
} }
return retVal; return retVal;
} }
@VisibleForTesting
void setFhirContext(FhirContext theFhirContext) {
myFhirCtx = theFhirContext;
}
} }

View File

@ -22,10 +22,6 @@ import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyS
import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.r4.model.Attachment;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Type;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -47,7 +43,6 @@ import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -59,8 +54,6 @@ import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyList;
@ -486,86 +479,6 @@ public class UploadTerminologyCommandTest {
uploadICD10UsingCompressedFile(theFhirVersion, theIncludeTls); uploadICD10UsingCompressedFile(theFhirVersion, theIncludeTls);
} }
@ParameterizedTest
@MethodSource("paramsProvider")
@SuppressWarnings("unused") // Both params for @BeforeEach
void testZipFileInParameters(String theFhirVersion, boolean theIncludeTls) {
final IBaseParameters inputParameters = switch (myCtx.getVersion().getVersion()) {
case DSTU2, DSTU2_HL7ORG, DSTU2_1 -> new org.hl7.fhir.dstu2.model.Parameters();
case DSTU3 -> new org.hl7.fhir.dstu3.model.Parameters();
case R4 -> new Parameters();
case R4B -> new org.hl7.fhir.r4b.model.Parameters();
case R5 -> new org.hl7.fhir.r5.model.Parameters();
};
final UploadTerminologyCommand uploadTerminologyCommand = new UploadTerminologyCommand();
uploadTerminologyCommand.setFhirContext(myCtx);
uploadTerminologyCommand.setTransferSizeBytes(1);
uploadTerminologyCommand.addFileToRequestBundle(inputParameters, "something.zip", new byte[] {1,2});
final String actualAttachmentUrl = getAttachmentUrl(inputParameters, myCtx);
assertTrue(actualAttachmentUrl.endsWith(".zip"));
}
private static String getAttachmentUrl(IBaseParameters theInputParameters, FhirContext theCtx) {
switch (theCtx.getVersion().getVersion()) {
case DSTU2:
case DSTU2_HL7ORG:
case DSTU2_1: {
assertInstanceOf(org.hl7.fhir.dstu2.model.Parameters.class, theInputParameters);
final org.hl7.fhir.dstu2.model.Parameters dstu2Parameters = (org.hl7.fhir.dstu2.model.Parameters) theInputParameters;
final List<org.hl7.fhir.dstu2.model.Parameters.ParametersParameterComponent> dstu2ParametersList = dstu2Parameters.getParameter();
final Optional<org.hl7.fhir.dstu2.model.Parameters.ParametersParameterComponent> optDstu2FileParam = dstu2ParametersList.stream().filter(param -> TerminologyUploaderProvider.PARAM_FILE.equals(param.getName())).findFirst();
assertTrue(optDstu2FileParam.isPresent());
final org.hl7.fhir.dstu2.model.Type dstu2Value = optDstu2FileParam.get().getValue();
assertInstanceOf(org.hl7.fhir.dstu2.model.Attachment.class, dstu2Value);
final org.hl7.fhir.dstu2.model.Attachment dstu2Attachment = (org.hl7.fhir.dstu2.model.Attachment) dstu2Value;
return dstu2Attachment.getUrl();
}
case DSTU3: {
assertInstanceOf(org.hl7.fhir.dstu3.model.Parameters.class, theInputParameters);
final org.hl7.fhir.dstu3.model.Parameters dstu3Parameters = (org.hl7.fhir.dstu3.model.Parameters) theInputParameters;
final List<org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent> dstu3ParametersList = dstu3Parameters.getParameter();
final Optional<org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent> optDstu3FileParam = dstu3ParametersList.stream().filter(param -> TerminologyUploaderProvider.PARAM_FILE.equals(param.getName())).findFirst();
assertTrue(optDstu3FileParam.isPresent());
final org.hl7.fhir.dstu3.model.Type dstu3Value = optDstu3FileParam.get().getValue();
assertInstanceOf(org.hl7.fhir.dstu3.model.Attachment.class, dstu3Value);
final org.hl7.fhir.dstu3.model.Attachment dstu3Attachment = (org.hl7.fhir.dstu3.model.Attachment) dstu3Value;
return dstu3Attachment.getUrl();
}
case R4: {
assertInstanceOf(Parameters.class, theInputParameters);
final Parameters r4Parameters = (Parameters) theInputParameters;
final Parameters.ParametersParameterComponent r4Parameter = r4Parameters.getParameter(TerminologyUploaderProvider.PARAM_FILE);
final Type r4Value = r4Parameter.getValue();
assertInstanceOf(Attachment.class, r4Value);
final Attachment r4Attachment = (Attachment) r4Value;
return r4Attachment.getUrl();
}
case R4B: {
assertInstanceOf(org.hl7.fhir.r4b.model.Parameters.class, theInputParameters);
final org.hl7.fhir.r4b.model.Parameters r4bParameters = (org.hl7.fhir.r4b.model.Parameters) theInputParameters;
final org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent r4bParameter = r4bParameters.getParameter(TerminologyUploaderProvider.PARAM_FILE);
final org.hl7.fhir.r4b.model.DataType value = r4bParameter.getValue();
assertInstanceOf(org.hl7.fhir.r4b.model.Attachment.class, value);
final org.hl7.fhir.r4b.model.Attachment r4bAttachment = (org.hl7.fhir.r4b.model.Attachment) value;
return r4bAttachment.getUrl();
}
case R5: {
assertInstanceOf(org.hl7.fhir.r5.model.Parameters.class, theInputParameters);
final org.hl7.fhir.r5.model.Parameters r4Parameters = (org.hl7.fhir.r5.model.Parameters) theInputParameters;
final org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent parameter = r4Parameters.getParameter(TerminologyUploaderProvider.PARAM_FILE);
final org.hl7.fhir.r5.model.DataType value = parameter.getValue();
assertInstanceOf(org.hl7.fhir.r5.model.Attachment.class, value);
final org.hl7.fhir.r5.model.Attachment attachment = (org.hl7.fhir.r5.model.Attachment) value;
return attachment.getUrl();
}
default:
throw new IllegalStateException("Unknown FHIR version: " + theCtx.getVersion().getVersion());
}
}
private void uploadICD10UsingCompressedFile(String theFhirVersion, boolean theIncludeTls) throws IOException { private void uploadICD10UsingCompressedFile(String theFhirVersion, boolean theIncludeTls) throws IOException {
if (FHIR_VERSION_DSTU3.equals(theFhirVersion)) { if (FHIR_VERSION_DSTU3.equals(theFhirVersion)) {
when(myTermLoaderSvc.loadIcd10cm(anyList(), any())).thenReturn(new UploadStatistics(100, new org.hl7.fhir.dstu3.model.IdType("CodeSystem/101"))); when(myTermLoaderSvc.loadIcd10cm(anyList(), any())).thenReturn(new UploadStatistics(100, new org.hl7.fhir.dstu3.model.IdType("CodeSystem/101")));

View File

@ -1,4 +0,0 @@
---
type: add
issue: 5861
title: "Enhance RuleBuilder code to support multiple instance IDs."

View File

@ -1,5 +0,0 @@
---
type: fix
issue: 5865
title: "Moving the Hibernate.Search annotation for text indexing from the lob column to the column added as part of the
PostgreSql LOB migration."

View File

@ -1,5 +0,0 @@
---
type: fix
issue: 5877
title: "Previously, updating a tokenParam with a value greater than 200 characters would raise a SQLException.
This issue has been fixed."

View File

@ -1,6 +0,0 @@
---
type: fix
issue: 5886
title: "Previously, either updating links on, or deleting one of two patients with non-numeric IDs linked to a golden
patient would result in a HAPI-0389 if there were survivorship rules.
This issue has been fixed for both the update links and delete cases."

View File

@ -1,7 +0,0 @@
---
type: fix
issue: 5888
title: "Updated documentation on binary_security_interceptor to specify using
`STORAGE_PRE_INITIATE_BULK_EXPORT` not `STORAGE_INITIATE_BULK_EXPORT` pointcut
to change bulk export parameters.
"

View File

@ -1,5 +0,0 @@
---
type: add
issue: 5890
title: "As part of the migration from LOB, provided the capability to force persisting data to LOB columns. The default
behavior is to not persist in lob columns."

View File

@ -1,6 +0,0 @@
---
type: fix
issue: 5893
title: "Previously, hapi-fhir-cli: upload-terminology failed with a HAPI-0862 error when uploading LOINC.
This has been fixed."

View File

@ -1,5 +0,0 @@
---
type: fix
issue: 5898
title: "Previously, triggering a `$meta` via GET on a new patient with Megascale configured resulted in error HAPI-0389. This has been corrected
This has been fixed."

View File

@ -1,4 +0,0 @@
---
type: add
issue: 5899
title: "The `MDM_POST_MERGE_GOLDEN_RESOURCES` now supports an additional parameter, of type `ca.uhn.fhir.mdm.model.MdmTransactionContext`. Thanks to Jens Villadsen for the contribution."

View File

@ -1,4 +0,0 @@
---
type: fix
issue: 5904
title: "Chained sort would exclude results that did not have resources matching the sort chain. These are now included, and sorted at the end."

View File

@ -1,4 +0,0 @@
---
type: fix
issue: 5915
title: "Previously, in some edge case scenarios the Bulk Export Rule Applier could accidentally permit a Patient type level bulk export request, even if the calling user only had permissions to a subset of patients. This has been corrected."

View File

@ -1,4 +0,0 @@
---
type: fix
issue: 5917
title: "Fix chained sorts on strings when using MS Sql"

View File

@ -14,9 +14,4 @@ This interceptor is intended to be subclassed. A simple example is shown below:
## Combining with Bulk Export ## Combining with Bulk Export
The `setBinarySecurityContextIdentifierSystem(..)` and `setBinarySecurityContextIdentifierValue(..)` properties on the `BulkExportJobParameters` object can be used to automatically populate the security context on Binary resources created by Bulk Export jobs with values that can be verified by this interceptor. The `setBinarySecurityContextIdentifierSystem(..)` and `setBinarySecurityContextIdentifierValue(..)` properties on the `BulkExportJobParameters` object can be used to automatically populate the security context on Binary resources created by Bulk Export jobs with values that can be verified by this interceptor. An interceptor on the `STORAGE_INITIATE_BULK_EXPORT` pointcut is the easiest way to set these properties when a new Bulk Export job is being kicked off.
An interceptor on the `STORAGE_PRE_INITIATE_BULK_EXPORT` pointcut is the recommended way to set these properties when a new Bulk Export job is being kicked off.
NB: Previous versions recommended using the `STORAGE_INITIATE_BULK_EXPORT` pointcut, but this is no longer the recommended way.
`STORAGE_PRE_INITIATE_BULK_EXPORT` pointcut is called before `STORAGE_INITIATE_BULK_EXPORT` and is thus guaranteed to be called before
any AuthorizationInterceptors.

View File

@ -26,7 +26,6 @@ import ca.uhn.fhir.jpa.dao.data.IBinaryStorageEntityDao;
import ca.uhn.fhir.jpa.model.entity.BinaryStorageEntity; import ca.uhn.fhir.jpa.model.entity.BinaryStorageEntity;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.hash.HashingInputStream; import com.google.common.hash.HashingInputStream;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import jakarta.annotation.Nonnull; import jakarta.annotation.Nonnull;
@ -60,8 +59,6 @@ public class DatabaseBinaryContentStorageSvcImpl extends BaseBinaryStorageSvcImp
@Autowired @Autowired
private IBinaryStorageEntityDao myBinaryStorageEntityDao; private IBinaryStorageEntityDao myBinaryStorageEntityDao;
private boolean mySupportLegacyLobServer = false;
@Nonnull @Nonnull
@Override @Override
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
@ -99,10 +96,9 @@ public class DatabaseBinaryContentStorageSvcImpl extends BaseBinaryStorageSvcImp
entity.setContentId(id); entity.setContentId(id);
entity.setStorageContentBin(loadedStream); entity.setStorageContentBin(loadedStream);
if (mySupportLegacyLobServer) { // TODO: remove writing Blob in a future release
Blob dataBlob = lobHelper.createBlob(loadedStream); Blob dataBlob = lobHelper.createBlob(loadedStream);
entity.setBlob(dataBlob); entity.setBlob(dataBlob);
}
// Update the entity with the final byte count and hash // Update the entity with the final byte count and hash
long bytes = countingInputStream.getByteCount(); long bytes = countingInputStream.getByteCount();
@ -173,11 +169,6 @@ public class DatabaseBinaryContentStorageSvcImpl extends BaseBinaryStorageSvcImp
return copyBinaryContentToByteArray(entityOpt); return copyBinaryContentToByteArray(entityOpt);
} }
public DatabaseBinaryContentStorageSvcImpl setSupportLegacyLobServer(boolean theSupportLegacyLobServer) {
mySupportLegacyLobServer = theSupportLegacyLobServer;
return this;
}
void copyBinaryContentToOutputStream(OutputStream theOutputStream, BinaryStorageEntity theEntity) void copyBinaryContentToOutputStream(OutputStream theOutputStream, BinaryStorageEntity theEntity)
throws IOException { throws IOException {
@ -221,10 +212,4 @@ public class DatabaseBinaryContentStorageSvcImpl extends BaseBinaryStorageSvcImp
return retVal; return retVal;
} }
@VisibleForTesting
public DatabaseBinaryContentStorageSvcImpl setEntityManagerForTesting(EntityManager theEntityManager) {
myEntityManager = theEntityManager;
return this;
}
} }

View File

@ -73,7 +73,6 @@ import ca.uhn.fhir.jpa.delete.DeleteConflictFinderService;
import ca.uhn.fhir.jpa.delete.DeleteConflictService; import ca.uhn.fhir.jpa.delete.DeleteConflictService;
import ca.uhn.fhir.jpa.delete.ThreadSafeResourceDeleterSvc; import ca.uhn.fhir.jpa.delete.ThreadSafeResourceDeleterSvc;
import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.entity.Search;
import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.esr.ExternallyStoredResourceServiceRegistry; import ca.uhn.fhir.jpa.esr.ExternallyStoredResourceServiceRegistry;
import ca.uhn.fhir.jpa.graphql.DaoRegistryGraphQLStorageServices; import ca.uhn.fhir.jpa.graphql.DaoRegistryGraphQLStorageServices;
import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor; import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor;
@ -155,8 +154,6 @@ import ca.uhn.fhir.jpa.term.TermCodeSystemStorageSvcImpl;
import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl; import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl;
import ca.uhn.fhir.jpa.term.TermReadSvcImpl; import ca.uhn.fhir.jpa.term.TermReadSvcImpl;
import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl; import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl;
import ca.uhn.fhir.jpa.term.ValueSetConceptAccumulator;
import ca.uhn.fhir.jpa.term.ValueSetConceptAccumulatorFactory;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc; import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc;
import ca.uhn.fhir.jpa.term.api.ITermReadSvc; import ca.uhn.fhir.jpa.term.api.ITermReadSvc;
@ -825,17 +822,6 @@ public class JpaConfig {
return new TermReadSvcImpl(); return new TermReadSvcImpl();
} }
@Bean
public ValueSetConceptAccumulatorFactory valueSetConceptAccumulatorFactory() {
return new ValueSetConceptAccumulatorFactory();
}
@Bean
@Scope("prototype")
public ValueSetConceptAccumulator valueSetConceptAccumulator(TermValueSet theTermValueSet) {
return valueSetConceptAccumulatorFactory().create(theTermValueSet);
}
@Bean @Bean
public ITermCodeSystemStorageSvc termCodeSystemStorageSvc() { public ITermCodeSystemStorageSvc termCodeSystemStorageSvc() {
return new TermCodeSystemStorageSvcImpl(); return new TermCodeSystemStorageSvcImpl();

View File

@ -1410,20 +1410,19 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
} }
@Override @Override
@Transactional
public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId, RequestDetails theRequest) { public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId, RequestDetails theRequest) {
return myTransactionService.withRequest(theRequest).execute(() -> { Set<TagDefinition> tagDefs = new HashSet<>();
Set<TagDefinition> tagDefs = new HashSet<>(); BaseHasResource entity = readEntity(theId, theRequest);
BaseHasResource entity = readEntity(theId, theRequest); for (BaseTag next : entity.getTags()) {
for (BaseTag next : entity.getTags()) { tagDefs.add(next.getTag());
tagDefs.add(next.getTag()); }
} MT retVal = toMetaDt(theType, tagDefs);
MT retVal = toMetaDt(theType, tagDefs);
retVal.setLastUpdated(entity.getUpdatedDate()); retVal.setLastUpdated(entity.getUpdatedDate());
retVal.setVersionId(Long.toString(entity.getVersion())); retVal.setVersionId(Long.toString(entity.getVersion()));
return retVal; return retVal;
});
} }
@Override @Override

View File

@ -24,7 +24,6 @@ import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum;
import ca.uhn.fhir.jpa.search.DeferConceptIndexingRoutingBinder; import ca.uhn.fhir.jpa.search.DeferConceptIndexingRoutingBinder;
import ca.uhn.fhir.util.ValidateUtil; import ca.uhn.fhir.util.ValidateUtil;
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.Nonnull; import jakarta.annotation.Nonnull;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -59,7 +58,10 @@ import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.RoutingBinderR
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyBinding; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyBinding;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue;
import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Coding;
import java.io.Serializable; import java.io.Serializable;
@ -175,11 +177,6 @@ public class TermConcept implements Serializable {
@Column(name = "PARENT_PIDS", nullable = true) @Column(name = "PARENT_PIDS", nullable = true)
private String myParentPids; private String myParentPids;
@FullTextField(
name = "myParentPids",
searchable = Searchable.YES,
projectable = Projectable.YES,
analyzer = "conceptParentPidsAnalyzer")
@Column(name = "PARENT_PIDS_VC", nullable = true, length = Length.LONG32) @Column(name = "PARENT_PIDS_VC", nullable = true, length = Length.LONG32)
private String myParentPidsVc; private String myParentPidsVc;
@ -192,9 +189,6 @@ public class TermConcept implements Serializable {
@Column(name = "CODE_SEQUENCE", nullable = true) @Column(name = "CODE_SEQUENCE", nullable = true)
private Integer mySequence; private Integer mySequence;
@Transient
private boolean mySupportLegacyLob = false;
public TermConcept() { public TermConcept() {
super(); super();
} }
@ -368,6 +362,13 @@ public class TermConcept implements Serializable {
return this; return this;
} }
@Transient
@FullTextField(
name = "myParentPids",
searchable = Searchable.YES,
projectable = Projectable.YES,
analyzer = "conceptParentPidsAnalyzer")
@IndexingDependency(derivedFrom = @ObjectPath({@PropertyValue(propertyName = "myParentPidsVc")}))
public String getParentPidsAsString() { public String getParentPidsAsString() {
return nonNull(myParentPidsVc) ? myParentPidsVc : myParentPids; return nonNull(myParentPidsVc) ? myParentPidsVc : myParentPids;
} }
@ -457,10 +458,6 @@ public class TermConcept implements Serializable {
ourLog.trace("Code {}/{} has parents {}", entity.getId(), entity.getCode(), entity.getParentPidsAsString()); ourLog.trace("Code {}/{} has parents {}", entity.getId(), entity.getCode(), entity.getParentPidsAsString());
} }
if (!mySupportLegacyLob) {
clearParentPidsLob();
}
} }
private void setParentPids(Set<Long> theParentPids) { private void setParentPids(Set<Long> theParentPids) {
@ -522,17 +519,4 @@ public class TermConcept implements Serializable {
public List<TermConcept> getChildCodes() { public List<TermConcept> getChildCodes() {
return getChildren().stream().map(TermConceptParentChildLink::getChild).collect(Collectors.toList()); return getChildren().stream().map(TermConceptParentChildLink::getChild).collect(Collectors.toList());
} }
public void flagForLegacyLobSupport(boolean theSupportLegacyLob) {
mySupportLegacyLob = theSupportLegacyLob;
}
private void clearParentPidsLob() {
myParentPids = null;
}
@VisibleForTesting
public boolean hasParentPidsLobForTesting() {
return nonNull(myParentPids);
}
} }

View File

@ -54,7 +54,6 @@ import org.hibernate.validator.constraints.NotBlank;
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.StringUtils.left; import static org.apache.commons.lang3.StringUtils.left;
import static org.apache.commons.lang3.StringUtils.length; import static org.apache.commons.lang3.StringUtils.length;
@ -308,15 +307,9 @@ public class TermConceptProperty implements Serializable {
return myId; return myId;
} }
public void performLegacyLobSupport(boolean theSupportLegacyLob) {
if (!theSupportLegacyLob) {
myValueLob = null;
}
}
@VisibleForTesting @VisibleForTesting
public boolean hasValueBlobForTesting() { public byte[] getValueBlobForTesting() {
return nonNull(myValueLob); return myValueLob;
} }
@VisibleForTesting @VisibleForTesting
@ -325,8 +318,8 @@ public class TermConceptProperty implements Serializable {
} }
@VisibleForTesting @VisibleForTesting
public boolean hasValueBinForTesting() { public byte[] getValueBinForTesting() {
return nonNull(myValueBin); return myValueBin;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -20,7 +20,6 @@
package ca.uhn.fhir.jpa.entity; package ca.uhn.fhir.jpa.entity;
import ca.uhn.fhir.util.ValidateUtil; import ca.uhn.fhir.util.ValidateUtil;
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.Nonnull; import jakarta.annotation.Nonnull;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -47,7 +46,6 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.apache.commons.lang3.StringUtils.left; import static org.apache.commons.lang3.StringUtils.left;
import static org.apache.commons.lang3.StringUtils.length; import static org.apache.commons.lang3.StringUtils.length;
@ -298,13 +296,4 @@ public class TermValueSetConcept implements Serializable {
? mySourceConceptDirectParentPidsVc ? mySourceConceptDirectParentPidsVc
: mySourceConceptDirectParentPids; : mySourceConceptDirectParentPids;
} }
public void clearSourceConceptDirectParentPidsLob() {
mySourceConceptDirectParentPids = null;
}
@VisibleForTesting
public boolean hasSourceConceptDirectParentPidsLob() {
return nonNull(mySourceConceptDirectParentPids);
}
} }

View File

@ -43,21 +43,20 @@ import java.sql.SQLException;
* because hibernate won't allow the view the function without it, but * because hibernate won't allow the view the function without it, but
*/ */
"SELECT CONCAT_WS(' ', vsc.PID, vscd.PID) AS PID, " + " vsc.PID AS CONCEPT_PID, " "SELECT CONCAT_WS(' ', vsc.PID, vscd.PID) AS PID, " + " vsc.PID AS CONCEPT_PID, "
+ " vsc.VALUESET_PID AS CONCEPT_VALUESET_PID, " + " vsc.VALUESET_PID AS CONCEPT_VALUESET_PID, "
+ " vsc.VALUESET_ORDER AS CONCEPT_VALUESET_ORDER, " + " vsc.VALUESET_ORDER AS CONCEPT_VALUESET_ORDER, "
+ " vsc.SYSTEM_URL AS CONCEPT_SYSTEM_URL, " + " vsc.SYSTEM_URL AS CONCEPT_SYSTEM_URL, "
+ " vsc.CODEVAL AS CONCEPT_CODEVAL, " + " vsc.CODEVAL AS CONCEPT_CODEVAL, "
+ " vsc.DISPLAY AS CONCEPT_DISPLAY, " + " vsc.DISPLAY AS CONCEPT_DISPLAY, "
+ " vsc.SYSTEM_VER AS SYSTEM_VER, " + " vsc.SYSTEM_VER AS SYSTEM_VER, "
+ " vsc.SOURCE_PID AS SOURCE_PID, " + " vsc.SOURCE_PID AS SOURCE_PID, "
+ " vsc.SOURCE_DIRECT_PARENT_PIDS AS SOURCE_DIRECT_PARENT_PIDS, " + " vsc.SOURCE_DIRECT_PARENT_PIDS AS SOURCE_DIRECT_PARENT_PIDS, "
+ " vsc.SOURCE_DIRECT_PARENT_PIDS_VC AS SOURCE_DIRECT_PARENT_PIDS_VC, " + " vscd.PID AS DESIGNATION_PID, "
+ " vscd.PID AS DESIGNATION_PID, " + " vscd.LANG AS DESIGNATION_LANG, "
+ " vscd.LANG AS DESIGNATION_LANG, " + " vscd.USE_SYSTEM AS DESIGNATION_USE_SYSTEM, "
+ " vscd.USE_SYSTEM AS DESIGNATION_USE_SYSTEM, " + " vscd.USE_CODE AS DESIGNATION_USE_CODE, "
+ " vscd.USE_CODE AS DESIGNATION_USE_CODE, " + " vscd.USE_DISPLAY AS DESIGNATION_USE_DISPLAY, "
+ " vscd.USE_DISPLAY AS DESIGNATION_USE_DISPLAY, " + " vscd.VAL AS DESIGNATION_VAL "
+ " vscd.VAL AS DESIGNATION_VAL "
+ "FROM TRM_VALUESET_CONCEPT vsc " + "FROM TRM_VALUESET_CONCEPT vsc "
+ "LEFT OUTER JOIN TRM_VALUESET_C_DESIGNATION vscd ON vsc.PID = vscd.VALUESET_CONCEPT_PID") + "LEFT OUTER JOIN TRM_VALUESET_C_DESIGNATION vscd ON vsc.PID = vscd.VALUESET_CONCEPT_PID")
public class TermValueSetConceptView implements Serializable, ITermValueSetConceptView { public class TermValueSetConceptView implements Serializable, ITermValueSetConceptView {
@ -113,9 +112,6 @@ public class TermValueSetConceptView implements Serializable, ITermValueSetConce
@Column(name = "SOURCE_DIRECT_PARENT_PIDS", nullable = true) @Column(name = "SOURCE_DIRECT_PARENT_PIDS", nullable = true)
private Clob mySourceConceptDirectParentPids; private Clob mySourceConceptDirectParentPids;
@Column(name = "SOURCE_DIRECT_PARENT_PIDS_VC", nullable = true)
private String mySourceConceptDirectParentPidsVc;
@Override @Override
public Long getSourceConceptPid() { public Long getSourceConceptPid() {
return mySourceConceptPid; return mySourceConceptPid;
@ -123,19 +119,14 @@ public class TermValueSetConceptView implements Serializable, ITermValueSetConce
@Override @Override
public String getSourceConceptDirectParentPids() { public String getSourceConceptDirectParentPids() {
String retVal = null;
if (mySourceConceptDirectParentPids != null) { if (mySourceConceptDirectParentPids != null) {
try (Reader characterStream = mySourceConceptDirectParentPids.getCharacterStream()) { try (Reader characterStream = mySourceConceptDirectParentPids.getCharacterStream()) {
retVal = IOUtils.toString(characterStream); return IOUtils.toString(characterStream);
} catch (IOException | SQLException e) { } catch (IOException | SQLException e) {
throw new InternalErrorException(Msg.code(828) + e); throw new InternalErrorException(Msg.code(828) + e);
} }
} else if (mySourceConceptDirectParentPidsVc != null) {
retVal = mySourceConceptDirectParentPidsVc;
} }
return null;
return retVal;
} }
@Override @Override

View File

@ -25,7 +25,6 @@ import ca.uhn.fhir.jpa.entity.BulkImportJobEntity;
import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.entity.Search;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
import ca.uhn.fhir.jpa.migrate.taskdef.ArbitrarySqlTask; import ca.uhn.fhir.jpa.migrate.taskdef.ArbitrarySqlTask;
import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask;
import ca.uhn.fhir.jpa.migrate.taskdef.CalculateHashesTask; import ca.uhn.fhir.jpa.migrate.taskdef.CalculateHashesTask;
import ca.uhn.fhir.jpa.migrate.taskdef.CalculateOrdinalDatesTask; import ca.uhn.fhir.jpa.migrate.taskdef.CalculateOrdinalDatesTask;
import ca.uhn.fhir.jpa.migrate.taskdef.ColumnTypeEnum; import ca.uhn.fhir.jpa.migrate.taskdef.ColumnTypeEnum;
@ -147,16 +146,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
binaryStorageBlobTable binaryStorageBlobTable
.renameColumn("20240404.1", "BLOB_ID", "CONTENT_ID") .renameColumn("20240404.1", "BLOB_ID", "CONTENT_ID")
.getLastAddedTask()
.ifPresent(BaseTask::doNothing);
binaryStorageBlobTable
.renameColumn("20240404.2", "BLOB_SIZE", "CONTENT_SIZE") .renameColumn("20240404.2", "BLOB_SIZE", "CONTENT_SIZE")
.getLastAddedTask() .renameColumn("20240404.3", "BLOB_HASH", "CONTENT_HASH");
.ifPresent(BaseTask::doNothing);
binaryStorageBlobTable
.renameColumn("20240404.3", "BLOB_HASH", "CONTENT_HASH")
.getLastAddedTask()
.ifPresent(BaseTask::doNothing);
binaryStorageBlobTable binaryStorageBlobTable
.modifyColumn("20240404.4", "BLOB_DATA") .modifyColumn("20240404.4", "BLOB_DATA")
@ -168,23 +159,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.nullable() .nullable()
.type(ColumnTypeEnum.BINARY); .type(ColumnTypeEnum.BINARY);
binaryStorageBlobTable binaryStorageBlobTable.migrateBlobToBinary("20240404.6", "BLOB_DATA", "STORAGE_CONTENT_BIN");
.migrateBlobToBinary("20240404.6", "BLOB_DATA", "STORAGE_CONTENT_BIN")
.doNothing();
binaryStorageBlobTable binaryStorageBlobTable.renameTable("20240404.7", "HFJ_BINARY_STORAGE");
.renameTable("20240404.7", "HFJ_BINARY_STORAGE")
.doNothing();
Builder.BuilderWithTableName binaryStorageTableFix = version.onTable("HFJ_BINARY_STORAGE");
binaryStorageTableFix.renameColumn("20240404.10", "CONTENT_ID", "BLOB_ID", true, true);
binaryStorageTableFix.renameColumn("20240404.20", "CONTENT_SIZE", "BLOB_SIZE", true, true);
binaryStorageTableFix.renameColumn("20240404.30", "CONTENT_HASH", "BLOB_HASH", true, true);
binaryStorageTableFix
.renameTable("20240404.40", "HFJ_BINARY_STORAGE_BLOB")
.failureAllowed();
} }
{ {
@ -195,9 +172,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.nullable() .nullable()
.type(ColumnTypeEnum.BINARY); .type(ColumnTypeEnum.BINARY);
termConceptPropertyTable termConceptPropertyTable.migrateBlobToBinary("20240409.2", "PROP_VAL_LOB", "PROP_VAL_BIN");
.migrateBlobToBinary("20240409.2", "PROP_VAL_LOB", "PROP_VAL_BIN")
.doNothing();
} }
{ {
@ -207,9 +182,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.nullable() .nullable()
.type(ColumnTypeEnum.TEXT); .type(ColumnTypeEnum.TEXT);
termValueSetConceptTable termValueSetConceptTable.migrateClobToText(
.migrateClobToText("20240409.4", "SOURCE_DIRECT_PARENT_PIDS", "SOURCE_DIRECT_PARENT_PIDS_VC") "20240409.4", "SOURCE_DIRECT_PARENT_PIDS", "SOURCE_DIRECT_PARENT_PIDS_VC");
.doNothing();
} }
{ {
@ -219,9 +193,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.nullable() .nullable()
.type(ColumnTypeEnum.TEXT); .type(ColumnTypeEnum.TEXT);
termConceptTable termConceptTable.migrateClobToText("20240410.2", "PARENT_PIDS", "PARENT_PIDS_VC");
.migrateClobToText("20240410.2", "PARENT_PIDS", "PARENT_PIDS_VC")
.doNothing();
} }
} }

View File

@ -37,7 +37,7 @@ public class RequestPartitionHelperSvc extends BaseRequestPartitionHelperSvc {
IPartitionLookupSvc myPartitionConfigSvc; IPartitionLookupSvc myPartitionConfigSvc;
@Override @Override
public RequestPartitionId validateAndNormalizePartitionIds(RequestPartitionId theRequestPartitionId) { protected RequestPartitionId validateAndNormalizePartitionIds(RequestPartitionId theRequestPartitionId) {
List<String> names = null; List<String> names = null;
for (int i = 0; i < theRequestPartitionId.getPartitionIds().size(); i++) { for (int i = 0; i < theRequestPartitionId.getPartitionIds().size(); i++) {
@ -59,7 +59,7 @@ public class RequestPartitionHelperSvc extends BaseRequestPartitionHelperSvc {
} }
} }
if (theRequestPartitionId.hasPartitionNames()) { if (theRequestPartitionId.getPartitionNames() != null) {
if (partition == null) { if (partition == null) {
Validate.isTrue( Validate.isTrue(
theRequestPartitionId.getPartitionIds().get(i) == null, theRequestPartitionId.getPartitionIds().get(i) == null,
@ -68,8 +68,8 @@ public class RequestPartitionHelperSvc extends BaseRequestPartitionHelperSvc {
} else { } else {
Validate.isTrue( Validate.isTrue(
Objects.equals( Objects.equals(
theRequestPartitionId.getPartitionNames().get(i), partition.getName()), theRequestPartitionId.getPartitionIds().get(i), partition.getId()),
"Partition name %s does not match ID %s", "Partition name %s does not match ID %n",
theRequestPartitionId.getPartitionNames().get(i), theRequestPartitionId.getPartitionNames().get(i),
theRequestPartitionId.getPartitionIds().get(i)); theRequestPartitionId.getPartitionIds().get(i));
} }
@ -94,7 +94,7 @@ public class RequestPartitionHelperSvc extends BaseRequestPartitionHelperSvc {
} }
@Override @Override
public RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId theRequestPartitionId) { protected RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId theRequestPartitionId) {
List<Integer> ids = null; List<Integer> ids = null;
for (int i = 0; i < theRequestPartitionId.getPartitionNames().size(); i++) { for (int i = 0; i < theRequestPartitionId.getPartitionNames().size(); i++) {
@ -122,9 +122,9 @@ public class RequestPartitionHelperSvc extends BaseRequestPartitionHelperSvc {
Validate.isTrue( Validate.isTrue(
Objects.equals( Objects.equals(
theRequestPartitionId.getPartitionIds().get(i), partition.getId()), theRequestPartitionId.getPartitionIds().get(i), partition.getId()),
"Partition ID %s does not match name %s", "Partition name %s does not match ID %n",
theRequestPartitionId.getPartitionIds().get(i), theRequestPartitionId.getPartitionNames().get(i),
theRequestPartitionId.getPartitionNames().get(i)); theRequestPartitionId.getPartitionIds().get(i));
} }
} else { } else {
if (ids == null) { if (ids == null) {

View File

@ -353,39 +353,26 @@ public class QueryStack {
throw new InvalidRequestException(Msg.code(2289) + msg); throw new InvalidRequestException(Msg.code(2289) + msg);
} }
// add a left-outer join to a predicate for the target type, then sort on value columns(s). BaseSearchParamPredicateBuilder chainedPredicateBuilder;
DbColumn[] sortColumn;
switch (targetSearchParameter.getParamType()) { switch (targetSearchParameter.getParamType()) {
case STRING: case STRING:
StringPredicateBuilder stringPredicateBuilder = mySqlBuilder.createStringPredicateBuilder(); StringPredicateBuilder stringPredicateBuilder = mySqlBuilder.createStringPredicateBuilder();
addSortCustomJoin( sortColumn = new DbColumn[] {stringPredicateBuilder.getColumnValueNormalized()};
resourceLinkPredicateBuilder.getColumnTargetResourceId(), chainedPredicateBuilder = stringPredicateBuilder;
stringPredicateBuilder, break;
stringPredicateBuilder.createHashIdentityPredicate(targetType, theChain));
mySqlBuilder.addSortString(
stringPredicateBuilder.getColumnValueNormalized(), theAscending, myUseAggregate);
return;
case TOKEN: case TOKEN:
TokenPredicateBuilder tokenPredicateBuilder = mySqlBuilder.createTokenPredicateBuilder(); TokenPredicateBuilder tokenPredicateBuilder = mySqlBuilder.createTokenPredicateBuilder();
addSortCustomJoin( sortColumn =
resourceLinkPredicateBuilder.getColumnTargetResourceId(), new DbColumn[] {tokenPredicateBuilder.getColumnSystem(), tokenPredicateBuilder.getColumnValue()
tokenPredicateBuilder, };
tokenPredicateBuilder.createHashIdentityPredicate(targetType, theChain)); chainedPredicateBuilder = tokenPredicateBuilder;
break;
mySqlBuilder.addSortString(tokenPredicateBuilder.getColumnSystem(), theAscending, myUseAggregate);
mySqlBuilder.addSortString(tokenPredicateBuilder.getColumnValue(), theAscending, myUseAggregate);
return;
case DATE: case DATE:
DatePredicateBuilder datePredicateBuilder = mySqlBuilder.createDatePredicateBuilder(); DatePredicateBuilder datePredicateBuilder = mySqlBuilder.createDatePredicateBuilder();
addSortCustomJoin( sortColumn = new DbColumn[] {datePredicateBuilder.getColumnValueLow()};
resourceLinkPredicateBuilder.getColumnTargetResourceId(), chainedPredicateBuilder = datePredicateBuilder;
datePredicateBuilder, break;
datePredicateBuilder.createHashIdentityPredicate(targetType, theChain));
mySqlBuilder.addSortDate(datePredicateBuilder.getColumnValueLow(), theAscending, myUseAggregate);
return;
/* /*
* Note that many of the options below aren't implemented because they * Note that many of the options below aren't implemented because they
@ -430,6 +417,14 @@ public class QueryStack {
+ theParamName + "." + theChain + " as this parameter. Can not sort on chains of target type: " + theParamName + "." + theChain + " as this parameter. Can not sort on chains of target type: "
+ targetSearchParameter.getParamType().name()); + targetSearchParameter.getParamType().name());
} }
addSortCustomJoin(resourceLinkPredicateBuilder.getColumnTargetResourceId(), chainedPredicateBuilder, null);
Condition predicate = chainedPredicateBuilder.createHashIdentityPredicate(targetType, theChain);
mySqlBuilder.addPredicate(predicate);
for (DbColumn next : sortColumn) {
mySqlBuilder.addSortNumeric(next, theAscending, myUseAggregate);
}
} }
public void addSortOnString(String theResourceName, String theParamName, boolean theAscending) { public void addSortOnString(String theResourceName, String theParamName, boolean theAscending) {

View File

@ -73,6 +73,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
@ -684,6 +685,26 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
} }
} }
private int ensureParentsSaved(Collection<TermConceptParentChildLink> theParents) {
ourLog.trace("Checking {} parents", theParents.size());
int retVal = 0;
for (TermConceptParentChildLink nextLink : theParents) {
if (nextLink.getRelationshipType() == TermConceptParentChildLink.RelationshipTypeEnum.ISA) {
TermConcept nextParent = nextLink.getParent();
retVal += ensureParentsSaved(nextParent.getParents());
if (nextParent.getId() == null) {
nextParent.setUpdated(new Date());
myConceptDao.saveAndFlush(nextParent);
retVal++;
ourLog.debug("Saved parent code {} and got id {}", nextParent.getCode(), nextParent.getId());
}
}
}
return retVal;
}
@Nonnull @Nonnull
private TermCodeSystem getOrCreateDistinctTermCodeSystem( private TermCodeSystem getOrCreateDistinctTermCodeSystem(
IResourcePersistentId theCodeSystemResourcePid, IResourcePersistentId theCodeSystemResourcePid,

View File

@ -46,8 +46,6 @@ public class TermConceptDaoSvc {
@Autowired @Autowired
protected ITermConceptDesignationDao myConceptDesignationDao; protected ITermConceptDesignationDao myConceptDesignationDao;
private boolean mySupportLegacyLob = false;
public int saveConcept(TermConcept theConcept) { public int saveConcept(TermConcept theConcept) {
int retVal = 0; int retVal = 0;
@ -72,11 +70,9 @@ public class TermConceptDaoSvc {
retVal++; retVal++;
theConcept.setIndexStatus(BaseHapiFhirDao.INDEX_STATUS_INDEXED); theConcept.setIndexStatus(BaseHapiFhirDao.INDEX_STATUS_INDEXED);
theConcept.setUpdated(new Date()); theConcept.setUpdated(new Date());
theConcept.flagForLegacyLobSupport(mySupportLegacyLob);
myConceptDao.save(theConcept); myConceptDao.save(theConcept);
for (TermConceptProperty next : theConcept.getProperties()) { for (TermConceptProperty next : theConcept.getProperties()) {
next.performLegacyLobSupport(mySupportLegacyLob);
myConceptPropertyDao.save(next); myConceptPropertyDao.save(next);
} }
@ -89,11 +85,6 @@ public class TermConceptDaoSvc {
return retVal; return retVal;
} }
public TermConceptDaoSvc setSupportLegacyLob(boolean theSupportLegacyLob) {
mySupportLegacyLob = theSupportLegacyLob;
return this;
}
private int ensureParentsSaved(Collection<TermConceptParentChildLink> theParents) { private int ensureParentsSaved(Collection<TermConceptParentChildLink> theParents) {
ourLog.trace("Checking {} parents", theParents.size()); ourLog.trace("Checking {} parents", theParents.size());
int retVal = 0; int retVal = 0;
@ -104,7 +95,6 @@ public class TermConceptDaoSvc {
retVal += ensureParentsSaved(nextParent.getParents()); retVal += ensureParentsSaved(nextParent.getParents());
if (nextParent.getId() == null) { if (nextParent.getId() == null) {
nextParent.setUpdated(new Date()); nextParent.setUpdated(new Date());
nextParent.flagForLegacyLobSupport(mySupportLegacyLob);
myConceptDao.saveAndFlush(nextParent); myConceptDao.saveAndFlush(nextParent);
retVal++; retVal++;
ourLog.debug("Saved parent code {} and got id {}", nextParent.getCode(), nextParent.getId()); ourLog.debug("Saved parent code {} and got id {}", nextParent.getCode(), nextParent.getId());

View File

@ -293,9 +293,6 @@ public class TermReadSvcImpl implements ITermReadSvc, IHasScheduledJobs {
@Autowired @Autowired
private InMemoryTerminologyServerValidationSupport myInMemoryTerminologyServerValidationSupport; private InMemoryTerminologyServerValidationSupport myInMemoryTerminologyServerValidationSupport;
@Autowired
private ValueSetConceptAccumulatorFactory myValueSetConceptAccumulatorFactory;
@Override @Override
public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) { public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) {
TermCodeSystemVersionDetails cs = getCurrentCodeSystemVersion(theSystem); TermCodeSystemVersionDetails cs = getCurrentCodeSystemVersion(theSystem);
@ -2396,11 +2393,11 @@ public class TermReadSvcImpl implements ITermReadSvc, IHasScheduledJobs {
}); });
assert valueSet != null; assert valueSet != null;
ValueSetConceptAccumulator valueSetConceptAccumulator = ValueSetConceptAccumulator accumulator = new ValueSetConceptAccumulator(
myValueSetConceptAccumulatorFactory.create(valueSetToExpand); valueSetToExpand, myTermValueSetDao, myValueSetConceptDao, myValueSetConceptDesignationDao);
ValueSetExpansionOptions options = new ValueSetExpansionOptions(); ValueSetExpansionOptions options = new ValueSetExpansionOptions();
options.setIncludeHierarchy(true); options.setIncludeHierarchy(true);
expandValueSet(options, valueSet, valueSetConceptAccumulator); expandValueSet(options, valueSet, accumulator);
// We are done with this ValueSet. // We are done with this ValueSet.
txTemplate.executeWithoutResult(t -> { txTemplate.executeWithoutResult(t -> {
@ -2415,7 +2412,7 @@ public class TermReadSvcImpl implements ITermReadSvc, IHasScheduledJobs {
"Pre-expanded ValueSet[{}] with URL[{}] - Saved {} concepts in {}", "Pre-expanded ValueSet[{}] with URL[{}] - Saved {} concepts in {}",
valueSet.getId(), valueSet.getId(),
valueSet.getUrl(), valueSet.getUrl(),
valueSetConceptAccumulator.getConceptsSaved(), accumulator.getConceptsSaved(),
sw); sw);
} catch (Exception e) { } catch (Exception e) {

View File

@ -48,8 +48,6 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator {
private int myDesignationsSaved; private int myDesignationsSaved;
private int myConceptsExcluded; private int myConceptsExcluded;
private boolean mySupportLegacyLob = false;
public ValueSetConceptAccumulator( public ValueSetConceptAccumulator(
@Nonnull TermValueSet theTermValueSet, @Nonnull TermValueSet theTermValueSet,
@Nonnull ITermValueSetDao theValueSetDao, @Nonnull ITermValueSetDao theValueSetDao,
@ -186,10 +184,6 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator {
concept.setSourceConceptPid(theSourceConceptPid); concept.setSourceConceptPid(theSourceConceptPid);
concept.setSourceConceptDirectParentPids(theSourceConceptDirectParentPids); concept.setSourceConceptDirectParentPids(theSourceConceptDirectParentPids);
if (!mySupportLegacyLob) {
concept.clearSourceConceptDirectParentPidsLob();
}
myValueSetConceptDao.save(concept); myValueSetConceptDao.save(concept);
myValueSetDao.save(myTermValueSet.incrementTotalConcepts()); myValueSetDao.save(myTermValueSet.incrementTotalConcepts());
@ -259,9 +253,4 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator {
// TODO: DM 2019-07-16 - If so, we should also populate TermValueSetConceptProperty entities here. // TODO: DM 2019-07-16 - If so, we should also populate TermValueSetConceptProperty entities here.
// TODO: DM 2019-07-30 - Expansions don't include the properties themselves; they may be needed to facilitate // TODO: DM 2019-07-30 - Expansions don't include the properties themselves; they may be needed to facilitate
// filters and parameterized expansions. // filters and parameterized expansions.
public ValueSetConceptAccumulator setSupportLegacyLob(boolean theSupportLegacyLob) {
mySupportLegacyLob = theSupportLegacyLob;
return this;
}
} }

View File

@ -1,51 +0,0 @@
/*-
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* 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%
*/
package ca.uhn.fhir.jpa.term;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao;
import ca.uhn.fhir.jpa.entity.TermValueSet;
import org.springframework.beans.factory.annotation.Autowired;
public class ValueSetConceptAccumulatorFactory {
@Autowired
private ITermValueSetDao myValueSetDao;
@Autowired
private ITermValueSetConceptDao myValueSetConceptDao;
@Autowired
private ITermValueSetConceptDesignationDao myValueSetConceptDesignationDao;
@Autowired
private JpaStorageSettings myStorageSettings;
public ValueSetConceptAccumulator create(TermValueSet theTermValueSet) {
ValueSetConceptAccumulator valueSetConceptAccumulator = new ValueSetConceptAccumulator(
theTermValueSet, myValueSetDao, myValueSetConceptDao, myValueSetConceptDesignationDao);
valueSetConceptAccumulator.setSupportLegacyLob(myStorageSettings.isWriteToLegacyLobColumns());
return valueSetConceptAccumulator;
}
}

View File

@ -19,7 +19,6 @@
*/ */
package ca.uhn.fhir.jpa.term.config; package ca.uhn.fhir.jpa.term.config;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.term.TermConceptDaoSvc; import ca.uhn.fhir.jpa.term.TermConceptDaoSvc;
import ca.uhn.fhir.jpa.term.TermDeferredStorageSvcImpl; import ca.uhn.fhir.jpa.term.TermDeferredStorageSvcImpl;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemDeleteJobSvc; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemDeleteJobSvc;
@ -42,7 +41,7 @@ public class TermCodeSystemConfig {
} }
@Bean @Bean
public TermConceptDaoSvc termConceptDaoSvc(JpaStorageSettings theJpaStorageSettings) { public TermConceptDaoSvc termConceptDaoSvc() {
return new TermConceptDaoSvc().setSupportLegacyLob(theJpaStorageSettings.isWriteToLegacyLobColumns()); return new TermConceptDaoSvc();
} }
} }

View File

@ -2,11 +2,8 @@ package ca.uhn.fhir.jpa.entity;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
@ -24,8 +21,8 @@ public class TermConceptPropertyTest {
termConceptProperty.setValue(ourVeryLongString); termConceptProperty.setValue(ourVeryLongString);
// then // then
assertThat(termConceptProperty.hasValueBlobForTesting(), equalTo(true)); assertThat(termConceptProperty.getValueBlobForTesting(), notNullValue());
assertThat(termConceptProperty.hasValueBinForTesting(), equalTo(true)); assertThat(termConceptProperty.getValueBinForTesting(), notNullValue());
} }
@Test @Test
@ -81,19 +78,4 @@ public class TermConceptPropertyTest {
assertThat(value, startsWith("a")); assertThat(value, startsWith("a"));
} }
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testSetValue_withSupportLegacyLob(boolean theSupportLegacyLob){
// given
TermConceptProperty termConceptProperty = new TermConceptProperty();
// when
termConceptProperty.setValue(ourVeryLongString);
termConceptProperty.performLegacyLobSupport(theSupportLegacyLob);
// then
assertThat(termConceptProperty.hasValueBinForTesting(), equalTo(true));
assertThat(termConceptProperty.hasValueBlobForTesting(), equalTo(theSupportLegacyLob));
}
} }

View File

@ -166,7 +166,6 @@ public class GoldenResourceMergerSvcImpl implements IGoldenResourceMergerSvc {
HookParams params = new HookParams(); HookParams params = new HookParams();
params.add(MdmMergeEvent.class, event); params.add(MdmMergeEvent.class, event);
params.add(RequestDetails.class, theParams.getRequestDetails()); params.add(RequestDetails.class, theParams.getRequestDetails());
params.add(MdmTransactionContext.class, theParams.getMdmTransactionContext());
myInterceptorBroadcaster.callHooks(Pointcut.MDM_POST_MERGE_GOLDEN_RESOURCES, params); myInterceptorBroadcaster.callHooks(Pointcut.MDM_POST_MERGE_GOLDEN_RESOURCES, params);
} }
} }

View File

@ -2,16 +2,11 @@ package ca.uhn.fhir.jpa.mdm.svc;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.mdm.api.IMdmSurvivorshipService; import ca.uhn.fhir.mdm.api.IMdmSurvivorshipService;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
import ca.uhn.fhir.mdm.api.MdmMatchOutcome;
import ca.uhn.fhir.mdm.model.MdmTransactionContext; import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -60,21 +55,4 @@ class MdmSurvivorshipSvcImplIT extends BaseMdmR4Test {
assertEquals(p1.getTelecom().size(), p1.getTelecom().size()); assertEquals(p1.getTelecom().size(), p1.getTelecom().size());
assertTrue(p2.getTelecomFirstRep().equalsDeep(p1.getTelecomFirstRep())); assertTrue(p2.getTelecomFirstRep().equalsDeep(p1.getTelecomFirstRep()));
} }
@Test
public void matchingPatientsWith_NON_Numeric_Ids_matches_doesNotThrow_NumberFormatException() {
final Patient frankPatient1 = buildFrankPatient();
frankPatient1.setId("patA");
myPatientDao.update(frankPatient1, new SystemRequestDetails());
final Patient frankPatient2 = buildFrankPatient();
frankPatient2.setId("patB");
myPatientDao.update(frankPatient2, new SystemRequestDetails());
final Patient goldenPatient = buildFrankPatient();
myPatientDao.create(goldenPatient, new SystemRequestDetails());
myMdmLinkDaoSvc.createOrUpdateLinkEntity(goldenPatient, frankPatient1, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myMdmLinkDaoSvc.createOrUpdateLinkEntity(goldenPatient, frankPatient2, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.MANUAL, createContextForCreate("Patient"));
myMdmSurvivorshipService.rebuildGoldenResourceWithSurvivorshipRules(goldenPatient, new MdmTransactionContext(MdmTransactionContext.OperationType.UPDATE_LINK));
}
} }

View File

@ -25,9 +25,8 @@ import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
@ -97,9 +96,8 @@ public class MdmSurvivorshipSvcImplTest {
} }
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
@ParameterizedTest @Test
@ValueSource(booleans = {true,false}) public void rebuildGoldenResourceCurrentLinksUsingSurvivorshipRules_withManyLinks_rebuildsInUpdateOrder() {
public void rebuildGoldenResourceCurrentLinksUsingSurvivorshipRules_withManyLinks_rebuildsInUpdateOrder(boolean theIsUseNonNumericId) {
// setup // setup
// create resources // create resources
Patient goldenPatient = new Patient(); Patient goldenPatient = new Patient();
@ -128,7 +126,7 @@ public class MdmSurvivorshipSvcImplTest {
patient.addIdentifier() patient.addIdentifier()
.setSystem("http://example.com") .setSystem("http://example.com")
.setValue("Value" + i); .setValue("Value" + i);
patient.setId("Patient/" + (theIsUseNonNumericId ? "pat"+i : Integer.toString(i))); patient.setId("Patient/" + i);
resources.add(patient); resources.add(patient);
MdmLinkJson link = createLinkJson( MdmLinkJson link = createLinkJson(
@ -151,13 +149,8 @@ public class MdmSurvivorshipSvcImplTest {
when(myDaoRegistry.getResourceDao(eq("Patient"))) when(myDaoRegistry.getResourceDao(eq("Patient")))
.thenReturn(resourceDao); .thenReturn(resourceDao);
AtomicInteger counter = new AtomicInteger(); AtomicInteger counter = new AtomicInteger();
if (theIsUseNonNumericId) { when(resourceDao.readByPid(any()))
when(resourceDao.read(any(), any())) .thenAnswer(params -> resources.get(counter.getAndIncrement()));
.thenAnswer(params -> resources.get(counter.getAndIncrement()));
} else {
when(resourceDao.readByPid(any()))
.thenAnswer(params -> resources.get(counter.getAndIncrement()));
}
Page<MdmLinkJson> linkPage = mock(Page.class); Page<MdmLinkJson> linkPage = mock(Page.class);
when(myMdmLinkQuerySvc.queryLinks(any(), any())) when(myMdmLinkQuerySvc.queryLinks(any(), any()))
.thenReturn(linkPage); .thenReturn(linkPage);

View File

@ -34,26 +34,23 @@ import java.util.Date;
import static java.util.Objects.nonNull; import static java.util.Objects.nonNull;
@Entity @Entity
@Table(name = "HFJ_BINARY_STORAGE_BLOB") @Table(name = "HFJ_BINARY_STORAGE")
public class BinaryStorageEntity { public class BinaryStorageEntity {
@Id @Id
@Column(name = "BLOB_ID", length = 200, nullable = false) @Column(name = "CONTENT_ID", length = 200, nullable = false)
// N.B GGG: Note that the `content id` is the same as the `externalized binary id`. // N.B GGG: Note that the `content id` is the same as the `externalized binary id`.
private String myContentId; private String myContentId;
@Column(name = "RESOURCE_ID", length = 100, nullable = false) @Column(name = "RESOURCE_ID", length = 100, nullable = false)
private String myResourceId; private String myResourceId;
@Column(name = "BLOB_SIZE", nullable = true) @Column(name = "CONTENT_SIZE", nullable = true)
private long mySize; private long mySize;
@Column(name = "CONTENT_TYPE", nullable = false, length = 100) @Column(name = "CONTENT_TYPE", nullable = false, length = 100)
private String myContentType; private String myContentType;
/**
* @deprecated
*/
@Deprecated(since = "7.2.0") @Deprecated(since = "7.2.0")
@Lob // TODO: VC column added in 7.2.0 - Remove non-VC column later @Lob // TODO: VC column added in 7.2.0 - Remove non-VC column later
@Column(name = "BLOB_DATA", nullable = true, insertable = true, updatable = false) @Column(name = "BLOB_DATA", nullable = true, insertable = true, updatable = false)
@ -66,7 +63,7 @@ public class BinaryStorageEntity {
@Column(name = "PUBLISHED_DATE", nullable = false) @Column(name = "PUBLISHED_DATE", nullable = false)
private Date myPublished; private Date myPublished;
@Column(name = "BLOB_HASH", length = 128, nullable = true) @Column(name = "CONTENT_HASH", length = 128, nullable = true)
private String myHash; private String myHash;
public Date getPublished() { public Date getPublished() {

View File

@ -156,30 +156,4 @@ public interface IRequestPartitionHelperSvc {
Set<Integer> toReadPartitions(@Nonnull RequestPartitionId theRequestPartitionId); Set<Integer> toReadPartitions(@Nonnull RequestPartitionId theRequestPartitionId);
boolean isResourcePartitionable(String theResourceType); boolean isResourcePartitionable(String theResourceType);
/**
* <b>No interceptors should be invoked by this method. It should ONLY be used when partition ids are
* known, but partition names are not.</b>
* <br/><br/>
* Ensures the list of partition ids inside the given {@link RequestPartitionId} correctly map to the
* list of partition names. If the list of partition names is empty, this method will map the correct
* partition names and return a normalized {@link RequestPartitionId}.
* <br/><br/>
* @param theRequestPartitionId - An unvalidated and unnormalized {@link RequestPartitionId}.
* @return - A {@link RequestPartitionId} with a normalized list of partition ids and partition names.
*/
RequestPartitionId validateAndNormalizePartitionIds(RequestPartitionId theRequestPartitionId);
/**
* <b>No interceptors should be invoked by this method. It should ONLY be used when partition names are
* known, but partition ids are not.</b>
* <br/><br/>
* Ensures the list of partition names inside the given {@link RequestPartitionId} correctly map to the
* list of partition ids. If the list of partition ids is empty, this method will map the correct
* partition ids and return a normalized {@link RequestPartitionId}.
* <br/><br/>
* @param theRequestPartitionId - An unvalidated and unnormalized {@link RequestPartitionId}.
* @return - A {@link RequestPartitionId} with a normalized list of partition ids and partition names.
*/
RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId theRequestPartitionId);
} }

View File

@ -1,35 +0,0 @@
/*-
* #%L
* HAPI FHIR Subscription Server
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* 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%
*/
package ca.uhn.fhir.jpa.subscription.config;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionQueryValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SubscriptionConfig {
@Bean
public SubscriptionQueryValidator subscriptionQueryValidator(
DaoRegistry theDaoRegistry, SubscriptionStrategyEvaluator theSubscriptionStrategyEvaluator) {
return new SubscriptionQueryValidator(theDaoRegistry, theSubscriptionStrategyEvaluator);
}
}

View File

@ -19,13 +19,15 @@
*/ */
package ca.uhn.fhir.jpa.subscription.submit.config; package ca.uhn.fhir.jpa.subscription.submit.config;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.dao.tx.IHapiTransactionService; import ca.uhn.fhir.jpa.dao.tx.IHapiTransactionService;
import ca.uhn.fhir.jpa.model.entity.StorageSettings; import ca.uhn.fhir.jpa.model.entity.StorageSettings;
import ca.uhn.fhir.jpa.subscription.async.AsyncResourceModifiedProcessingSchedulerSvc; import ca.uhn.fhir.jpa.subscription.async.AsyncResourceModifiedProcessingSchedulerSvc;
import ca.uhn.fhir.jpa.subscription.async.AsyncResourceModifiedSubmitterSvc; import ca.uhn.fhir.jpa.subscription.async.AsyncResourceModifiedSubmitterSvc;
import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory;
import ca.uhn.fhir.jpa.subscription.config.SubscriptionConfig; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator;
import ca.uhn.fhir.jpa.subscription.model.config.SubscriptionModelConfig; import ca.uhn.fhir.jpa.subscription.model.config.SubscriptionModelConfig;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionQueryValidator;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionSubmitInterceptorLoader; import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionSubmitInterceptorLoader;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionValidatingInterceptor; import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionValidatingInterceptor;
import ca.uhn.fhir.jpa.subscription.submit.svc.ResourceModifiedSubmitterSvc; import ca.uhn.fhir.jpa.subscription.submit.svc.ResourceModifiedSubmitterSvc;
@ -43,7 +45,7 @@ import org.springframework.context.annotation.Lazy;
* matching queue for processing * matching queue for processing
*/ */
@Configuration @Configuration
@Import({SubscriptionModelConfig.class, SubscriptionMatcherInterceptorConfig.class, SubscriptionConfig.class}) @Import({SubscriptionModelConfig.class, SubscriptionMatcherInterceptorConfig.class})
public class SubscriptionSubmitterConfig { public class SubscriptionSubmitterConfig {
@Bean @Bean
@ -51,6 +53,12 @@ public class SubscriptionSubmitterConfig {
return new SubscriptionValidatingInterceptor(); return new SubscriptionValidatingInterceptor();
} }
@Bean
public SubscriptionQueryValidator subscriptionQueryValidator(
DaoRegistry theDaoRegistry, SubscriptionStrategyEvaluator theSubscriptionStrategyEvaluator) {
return new SubscriptionQueryValidator(theDaoRegistry, theSubscriptionStrategyEvaluator);
}
@Bean @Bean
public SubscriptionSubmitInterceptorLoader subscriptionMatcherInterceptorLoader() { public SubscriptionSubmitInterceptorLoader subscriptionMatcherInterceptorLoader() {
return new SubscriptionSubmitInterceptorLoader(); return new SubscriptionSubmitInterceptorLoader();

View File

@ -22,15 +22,13 @@ package ca.uhn.fhir.jpa.topic;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher; import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher;
import ca.uhn.fhir.jpa.subscription.config.SubscriptionConfig; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionQueryValidator; import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionQueryValidator;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@Configuration @Configuration
@Import(SubscriptionConfig.class)
public class SubscriptionTopicConfig { public class SubscriptionTopicConfig {
@Bean @Bean
SubscriptionTopicMatchingSubscriber subscriptionTopicMatchingSubscriber(FhirContext theFhirContext) { SubscriptionTopicMatchingSubscriber subscriptionTopicMatchingSubscriber(FhirContext theFhirContext) {
@ -78,6 +76,13 @@ public class SubscriptionTopicConfig {
} }
} }
@Bean
@Lazy
public SubscriptionQueryValidator subscriptionQueryValidator(
DaoRegistry theDaoRegistry, SubscriptionStrategyEvaluator theSubscriptionStrategyEvaluator) {
return new SubscriptionQueryValidator(theDaoRegistry, theSubscriptionStrategyEvaluator);
}
@Bean @Bean
SubscriptionTopicValidatingInterceptor subscriptionTopicValidatingInterceptor( SubscriptionTopicValidatingInterceptor subscriptionTopicValidatingInterceptor(
FhirContext theFhirContext, SubscriptionQueryValidator theSubscriptionQueryValidator) { FhirContext theFhirContext, SubscriptionQueryValidator theSubscriptionQueryValidator) {

View File

@ -7,12 +7,8 @@ import ca.uhn.fhir.jpa.model.entity.BinaryStorageEntity;
import ca.uhn.fhir.jpa.test.BaseJpaR4Test; import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import jakarta.persistence.EntityManager;
import org.hibernate.LobHelper;
import org.hibernate.Session;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -28,7 +24,6 @@ import java.sql.SQLException;
import java.util.Optional; import java.util.Optional;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.matchesPattern;
@ -39,7 +34,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -287,7 +281,7 @@ public class DatabaseBinaryContentStorageSvcImplTest extends BaseJpaR4Test {
} }
@Test @Test
public void testStoreBinaryContent_byDefault_writesByteArrayOnly() throws IOException { public void testStoreBinaryContent_writesBlobAndByteArray() throws IOException {
// given // given
ByteArrayInputStream inputStream = new ByteArrayInputStream(SOME_BYTES); ByteArrayInputStream inputStream = new ByteArrayInputStream(SOME_BYTES);
String contentType = "image/png"; String contentType = "image/png";
@ -302,41 +296,11 @@ public class DatabaseBinaryContentStorageSvcImplTest extends BaseJpaR4Test {
// then // then
assertThat(binaryStorageEntity.hasStorageContent(), is(true)); assertThat(binaryStorageEntity.hasStorageContent(), is(true));
assertThat(binaryStorageEntity.hasBlob(), is(false)); assertThat(binaryStorageEntity.hasBlob(), is(true));
}); });
} }
@Test
public void testStoreBinaryContent_whenSupportingLegacyBlobServer_willStoreToBlobAndBinaryArray() throws IOException {
ArgumentCaptor<BinaryStorageEntity> captor = ArgumentCaptor.forClass(BinaryStorageEntity.class);
EntityManager mockedEntityManager = mock(EntityManager.class);
Session mockedSession = mock(Session.class);
LobHelper mockedLobHelper = mock(LobHelper.class);
when(mockedEntityManager.getDelegate()).thenReturn(mockedSession);
when(mockedSession.getLobHelper()).thenReturn(mockedLobHelper);
when(mockedLobHelper.createBlob(any())).thenReturn(mock(Blob.class));
// given
DatabaseBinaryContentStorageSvcImpl svc = new DatabaseBinaryContentStorageSvcImpl()
.setSupportLegacyLobServer(true)
.setEntityManagerForTesting(mockedEntityManager);
ByteArrayInputStream inputStream = new ByteArrayInputStream(SOME_BYTES);
String contentType = "image/png";
IdType resourceId = new IdType("Binary/123");
// when
svc.storeBinaryContent(resourceId, null, contentType, inputStream, new ServletRequestDetails());
// then
verify(mockedEntityManager, times(1)).persist(captor.capture());
BinaryStorageEntity capturedBinaryStorageEntity = captor.getValue();
assertThat(capturedBinaryStorageEntity.hasBlob(), equalTo(true));
assertThat(capturedBinaryStorageEntity.hasStorageContent(), equalTo(true));
}
@Configuration @Configuration
public static class MyConfig { public static class MyConfig {

View File

@ -9,11 +9,8 @@ import ca.uhn.fhir.jpa.test.config.TestHSearchAddInConfig;
import ca.uhn.fhir.jpa.test.config.TestR4Config; import ca.uhn.fhir.jpa.test.config.TestR4Config;
import ca.uhn.fhir.jpa.util.SqlQuery; import ca.uhn.fhir.jpa.util.SqlQuery;
import ca.uhn.fhir.jpa.util.SqlQueryList; import ca.uhn.fhir.jpa.util.SqlQueryList;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.storage.test.DaoTestDataBuilder; import ca.uhn.fhir.storage.test.DaoTestDataBuilder;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -36,8 +33,6 @@ import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* Sandbox for implementing queries. * Sandbox for implementing queries.
@ -142,28 +137,6 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest {
myTestDaoSearch.assertSearchFindsInOrder("reverse sort by server assigned id", "Patient?family=smith&_sort=-_pid", id3,id2,id1); myTestDaoSearch.assertSearchFindsInOrder("reverse sort by server assigned id", "Patient?family=smith&_sort=-_pid", id3,id2,id1);
} }
@Test
void testChainedSort() {
final IIdType practitionerId = myDataBuilder.createPractitioner(myDataBuilder.withFamily("Jones"));
final String id1 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithy")).getIdPart();
final String id2 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithwick")).getIdPart();
final String id3 = myDataBuilder.createPatient(
myDataBuilder.withFamily("Smith"),
myDataBuilder.withReference("generalPractitioner", practitionerId)).getIdPart();
final IBundleProvider iBundleProvider = myTestDaoSearch.searchForBundleProvider("Patient?_total=ACCURATE&_sort=Practitioner:general-practitioner.family");
assertEquals(3, iBundleProvider.size());
final List<IBaseResource> allResources = iBundleProvider.getAllResources();
assertEquals(3, iBundleProvider.size());
assertEquals(3, allResources.size());
final List<String> actualIds = allResources.stream().map(IBaseResource::getIdElement).map(IIdType::getIdPart).toList();
assertTrue(actualIds.containsAll(List.of(id1, id2, id3)));
}
public static final class TestDirtiesContextTestExecutionListener extends DirtiesContextTestExecutionListener { public static final class TestDirtiesContextTestExecutionListener extends DirtiesContextTestExecutionListener {
@Override @Override

View File

@ -1,189 +1,74 @@
package ca.uhn.fhir.jpa.partition; package ca.uhn.fhir.jpa.partition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.dao.data.IPartitionDao;
import ca.uhn.fhir.jpa.entity.PartitionEntity; import ca.uhn.fhir.jpa.entity.PartitionEntity;
import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails; import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class RequestPartitionHelperSvcTest extends BaseJpaR4Test { class RequestPartitionHelperSvcTest {
static final Integer PARTITION_ID = 2401;
static final String PARTITION_NAME = "JIMMY";
static final PartitionEntity ourPartitionEntity = new PartitionEntity().setName(PARTITION_NAME);
static final int PARTITION_ID_1 = 1; @Mock
static final String PARTITION_NAME_1 = "SOME-PARTITION-1";
static final int PARTITION_ID_2 = 2;
static final String PARTITION_NAME_2 = "SOME-PARTITION-2";
static final int UNKNOWN_PARTITION_ID = 1_000_000;
static final String UNKNOWN_PARTITION_NAME = "UNKNOWN";
@Autowired
IPartitionDao myPartitionDao;
@Autowired
PartitionSettings myPartitionSettings; PartitionSettings myPartitionSettings;
@Autowired @Mock
RequestPartitionHelperSvc mySvc; IPartitionLookupSvc myPartitionLookupSvc;
@Mock
FhirContext myFhirContext;
@Mock
IInterceptorBroadcaster myInterceptorBroadcaster;
Patient myPatient; @InjectMocks
RequestPartitionHelperSvc mySvc = new RequestPartitionHelperSvc();
@BeforeEach
public void before(){
myPartitionDao.deleteAll();
myPartitionSettings.setPartitioningEnabled(true);
myPatient = new Patient();
myPatient.setId(new IdType("Patient", "123", "1"));
}
@Test @Test
public void testDetermineReadPartitionForSystemRequest_withPartitionIdOnly_returnsCorrectPartition() { public void determineReadPartitionForSystemRequest() {
// setup // setup
PartitionEntity partitionEntity = createPartition1();
SystemRequestDetails srd = new SystemRequestDetails(); SystemRequestDetails srd = new SystemRequestDetails();
srd.setRequestPartitionId(RequestPartitionId.fromPartitionId(partitionEntity.getId())); RequestPartitionId requestPartitionId = RequestPartitionId.fromPartitionId(PARTITION_ID);
srd.setRequestPartitionId(requestPartitionId);
when(myPartitionSettings.isPartitioningEnabled()).thenReturn(true);
when(myPartitionLookupSvc.getPartitionById(PARTITION_ID)).thenReturn(ourPartitionEntity);
// execute // execute
RequestPartitionId result = mySvc.determineReadPartitionForRequestForRead(srd, myPatient.fhirType(), myPatient.getIdElement()); RequestPartitionId result = mySvc.determineReadPartitionForRequestForRead(srd, "Patient", new IdType("Patient/123"));
// verify // verify
assertEquals(PARTITION_ID_1, result.getFirstPartitionIdOrNull()); assertEquals(PARTITION_ID, result.getFirstPartitionIdOrNull());
assertEquals(PARTITION_NAME_1, result.getFirstPartitionNameOrNull()); assertEquals(PARTITION_NAME, result.getFirstPartitionNameOrNull());
} }
@Test @Test
public void testDetermineCreatePartitionForRequest_withPartitionIdOnly_returnsCorrectPartition() { public void determineCreatePartitionForSystemRequest() {
// setup // setup
PartitionEntity partitionEntity = createPartition1();
SystemRequestDetails srd = new SystemRequestDetails(); SystemRequestDetails srd = new SystemRequestDetails();
srd.setRequestPartitionId(RequestPartitionId.fromPartitionId(partitionEntity.getId())); RequestPartitionId requestPartitionId = RequestPartitionId.fromPartitionId(PARTITION_ID);
srd.setRequestPartitionId(requestPartitionId);
when(myPartitionSettings.isPartitioningEnabled()).thenReturn(true);
when(myPartitionLookupSvc.getPartitionById(PARTITION_ID)).thenReturn(ourPartitionEntity);
Patient resource = new Patient();
when(myFhirContext.getResourceType(resource)).thenReturn("Patient");
// execute // execute
Patient patient = new Patient(); RequestPartitionId result = mySvc.determineCreatePartitionForRequest(srd, resource, "Patient");
RequestPartitionId result = mySvc.determineCreatePartitionForRequest(srd, patient, patient.fhirType());
// verify // verify
assertEquals(PARTITION_ID_1, result.getFirstPartitionIdOrNull()); assertEquals(PARTITION_ID, result.getFirstPartitionIdOrNull());
assertEquals(PARTITION_NAME_1, result.getFirstPartitionNameOrNull()); assertEquals(PARTITION_NAME, result.getFirstPartitionNameOrNull());
} }
@Test
public void testValidateAndNormalizePartitionIds_withPartitionIdOnly_populatesPartitionName(){
PartitionEntity partitionEntity = createPartition1();
RequestPartitionId partitionId = RequestPartitionId.fromPartitionId(partitionEntity.getId());
RequestPartitionId result = mySvc.validateAndNormalizePartitionIds(partitionId);
assertEquals(PARTITION_ID_1, result.getFirstPartitionIdOrNull());
assertEquals(PARTITION_NAME_1, result.getFirstPartitionNameOrNull());
}
@Test
public void testValidateAndNormalizePartitionIds_withUnknownId_throwsException(){
RequestPartitionId partitionId = RequestPartitionId.fromPartitionId(UNKNOWN_PARTITION_ID);
try{
mySvc.validateAndNormalizePartitionIds(partitionId);
fail();
} catch (ResourceNotFoundException e){
assertTrue(e.getMessage().contains("No partition exists with ID 1,000,000"));
}
}
@Test
public void testValidateAndNormalizePartitionIds_withIdAndInvalidName_throwsException(){
createPartition1();
RequestPartitionId partitionId = RequestPartitionId.fromPartitionIdAndName(PARTITION_ID_1, UNKNOWN_PARTITION_NAME);
try{
mySvc.validateAndNormalizePartitionIds(partitionId);
fail();
} catch (IllegalArgumentException e){
assertTrue(e.getMessage().contains("Partition name UNKNOWN does not match ID 1"));
}
}
@Test
public void testValidateAndNormalizePartitionIds_withMultiplePartitionIdOnly_populatesPartitionNames(){
PartitionEntity partitionEntity1 = createPartition1();
PartitionEntity partitionEntity2 = createPartition2();
RequestPartitionId partitionId = RequestPartitionId.fromPartitionIds(partitionEntity1.getId(), partitionEntity2.getId());
RequestPartitionId result = mySvc.validateAndNormalizePartitionIds(partitionId);
assertTrue(result.getPartitionIds().containsAll(Set.of(PARTITION_ID_1, PARTITION_ID_2)));
assertNotNull(result.getPartitionNames());
assertTrue(result.getPartitionNames().containsAll(Set.of(PARTITION_NAME_1, PARTITION_NAME_2)));
}
@Test
public void testValidateAndNormalizePartitionNames_withPartitionNameOnly_populatesPartitionId(){
PartitionEntity partitionEntity = createPartition1();
RequestPartitionId partitionId = RequestPartitionId.fromPartitionName(partitionEntity.getName());
RequestPartitionId result = mySvc.validateAndNormalizePartitionNames(partitionId);
assertEquals(PARTITION_ID_1, result.getFirstPartitionIdOrNull());
assertEquals(PARTITION_NAME_1, result.getFirstPartitionNameOrNull());
}
@Test
public void testValidateAndNormalizePartitionNames_withMultiplePartitionNamesOnly_populatesPartitionIds(){
PartitionEntity partitionEntity1 = createPartition1();
PartitionEntity partitionEntity2 = createPartition2();
RequestPartitionId partitionId = RequestPartitionId.fromPartitionNames(partitionEntity1.getName(), partitionEntity2.getName());
RequestPartitionId result = mySvc.validateAndNormalizePartitionNames(partitionId);
assertTrue(result.getPartitionIds().containsAll(Set.of(PARTITION_ID_1, PARTITION_ID_2)));
assertNotNull(result.getPartitionNames());
assertTrue(result.getPartitionNames().containsAll(Set.of(PARTITION_NAME_1, PARTITION_NAME_2)));
}
@Test
public void testValidateAndNormalizePartitionNames_withUnknownName_throwsException(){
RequestPartitionId partitionId = RequestPartitionId.fromPartitionName(UNKNOWN_PARTITION_NAME);
try{
mySvc.validateAndNormalizePartitionNames(partitionId);
fail();
} catch (ResourceNotFoundException e){
assertTrue(e.getMessage().contains("Partition name \"UNKNOWN\" is not valid"));
}
}
@Test
public void testValidateAndNormalizePartitionNames_withNameAndInvalidId_throwsException(){
createPartition1();
RequestPartitionId partitionId = RequestPartitionId.fromPartitionIdAndName(UNKNOWN_PARTITION_ID, PARTITION_NAME_1);
try{
mySvc.validateAndNormalizePartitionNames(partitionId);
fail();
} catch (IllegalArgumentException e){
assertTrue(e.getMessage().contains("Partition ID 1000000 does not match name SOME-PARTITION-1"));
}
}
private PartitionEntity createPartition1() {
return myPartitionDao.save(new PartitionEntity().setId(PARTITION_ID_1).setName(PARTITION_NAME_1));
}
private PartitionEntity createPartition2() {
return myPartitionDao.save(new PartitionEntity().setId(PARTITION_ID_2).setName(PARTITION_NAME_2));
}
} }

View File

@ -884,16 +884,6 @@ public class GiantTransactionPerfTest {
return true; return true;
} }
@Override
public RequestPartitionId validateAndNormalizePartitionIds(RequestPartitionId theRequestPartitionId) {
return RequestPartitionId.defaultPartition();
}
@Override
public RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId theRequestPartitionId) {
return RequestPartitionId.defaultPartition();
}
} }

View File

@ -2,7 +2,6 @@ package ca.uhn.fhir.jpa.dao.r5;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.dao.TestDaoSearch;
import ca.uhn.fhir.jpa.model.entity.StorageSettings; import ca.uhn.fhir.jpa.model.entity.StorageSettings;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.test.config.TestHSearchAddInConfig; import ca.uhn.fhir.jpa.test.config.TestHSearchAddInConfig;
@ -13,8 +12,6 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.BundleBuilder; import ca.uhn.fhir.util.BundleBuilder;
import ca.uhn.fhir.util.HapiExtensions; import ca.uhn.fhir.util.HapiExtensions;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r5.model.Composition; import org.hl7.fhir.r5.model.Composition;
import org.hl7.fhir.r5.model.IdType; import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.Bundle; import org.hl7.fhir.r5.model.Bundle;
@ -32,7 +29,6 @@ import org.hl7.fhir.r5.model.SearchParameter;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import jakarta.annotation.Nonnull; import jakarta.annotation.Nonnull;
@ -45,10 +41,9 @@ import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
@ContextConfiguration(classes = { TestHSearchAddInConfig.NoFT.class, TestDaoSearch.Config.class }) @ContextConfiguration(classes = TestHSearchAddInConfig.NoFT.class)
@SuppressWarnings({"Duplicates"}) @SuppressWarnings({"Duplicates"})
public class UpliftedRefchainsAndChainedSortingR5Test extends BaseJpaR5Test { public class UpliftedRefchainsAndChainedSortingR5Test extends BaseJpaR5Test {
public static final String PRACTITIONER_PR1 = "Practitioner/PR1"; public static final String PRACTITIONER_PR1 = "Practitioner/PR1";
@ -59,8 +54,6 @@ public class UpliftedRefchainsAndChainedSortingR5Test extends BaseJpaR5Test {
public static final String ENCOUNTER_E2 = "Encounter/E2"; public static final String ENCOUNTER_E2 = "Encounter/E2";
public static final String ENCOUNTER_E3 = "Encounter/E3"; public static final String ENCOUNTER_E3 = "Encounter/E3";
public static final String ORGANIZATION_O1 = "Organization/O1"; public static final String ORGANIZATION_O1 = "Organization/O1";
@Autowired
protected TestDaoSearch myTestDaoSearch;
@Override @Override
@BeforeEach @BeforeEach
@ -874,47 +867,6 @@ public class UpliftedRefchainsAndChainedSortingR5Test extends BaseJpaR5Test {
assertEquals(1, countMatches(querySql, "HFJ_RES_LINK"), querySql); assertEquals(1, countMatches(querySql, "HFJ_RES_LINK"), querySql);
} }
@Test
void testChainedSortWithNulls() {
final IIdType practitionerId1 = createPractitioner(withFamily("Chan"));
final IIdType practitionerId2 = createPractitioner(withFamily("Jones"));
final String id1 = createPatient(withFamily("Smithy")).getIdPart();
final String id2 = createPatient(withFamily("Smithwick"),
withReference("generalPractitioner", practitionerId2)).getIdPart();
final String id3 = createPatient(
withFamily("Smith"),
withReference("generalPractitioner", practitionerId1)).getIdPart();
final IBundleProvider iBundleProvider = myTestDaoSearch.searchForBundleProvider("Patient?_total=ACCURATE&_sort=Practitioner:general-practitioner.family");
final List<IBaseResource> allResources = iBundleProvider.getAllResources();
assertEquals(3, iBundleProvider.size());
assertEquals(3, allResources.size());
final List<String> actualIds = allResources.stream().map(IBaseResource::getIdElement).map(IIdType::getIdPart).toList();
assertTrue(actualIds.containsAll(List.of(id1, id2, id3)));
}
@Test
void testChainedReverseStringSort() {
final IIdType practitionerId = createPractitioner(withFamily("Jones"));
final String id1 = createPatient(withFamily("Smithy")).getIdPart();
final String id2 = createPatient(withFamily("Smithwick")).getIdPart();
final String id3 = createPatient(
withFamily("Smith"),
withReference("generalPractitioner", practitionerId)).getIdPart();
final IBundleProvider iBundleProvider = myTestDaoSearch.searchForBundleProvider("Patient?_total=ACCURATE&_sort=-Practitioner:general-practitioner.family");
assertEquals(3, iBundleProvider.size());
final List<IBaseResource> allResources = iBundleProvider.getAllResources();
final List<String> actualIds = allResources.stream().map(IBaseResource::getIdElement).map(IIdType::getIdPart).toList();
assertTrue(actualIds.containsAll(List.of(id3, id2, id1)));
}
/** /**
* Observation:focus is a Reference(Any) so it can't be used in a sort chain because * Observation:focus is a Reference(Any) so it can't be used in a sort chain because
* this would be horribly, horribly inefficient. * this would be horribly, horribly inefficient.

View File

@ -1,24 +1,38 @@
package ca.uhn.fhir.jpa.dao.r5.database; package ca.uhn.fhir.jpa.dao.r5.database;
import ca.uhn.fhir.batch2.jobs.export.BulkDataExportProvider;
import ca.uhn.fhir.batch2.jobs.expunge.DeleteExpungeProvider;
import ca.uhn.fhir.batch2.jobs.reindex.ReindexProvider;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoPatient;
import ca.uhn.fhir.jpa.dao.TestDaoSearch; import ca.uhn.fhir.jpa.api.dao.PatientEverythingParameters;
import ca.uhn.fhir.jpa.embedded.JpaEmbeddedDatabase; import ca.uhn.fhir.jpa.embedded.JpaEmbeddedDatabase;
import ca.uhn.fhir.jpa.fql.provider.HfqlRestProvider;
import ca.uhn.fhir.jpa.graphql.GraphQLProvider;
import ca.uhn.fhir.jpa.migrate.HapiMigrationStorageSvc; import ca.uhn.fhir.jpa.migrate.HapiMigrationStorageSvc;
import ca.uhn.fhir.jpa.migrate.MigrationTaskList; import ca.uhn.fhir.jpa.migrate.MigrationTaskList;
import ca.uhn.fhir.jpa.migrate.SchemaMigrator; import ca.uhn.fhir.jpa.migrate.SchemaMigrator;
import ca.uhn.fhir.jpa.migrate.dao.HapiMigrationDao; import ca.uhn.fhir.jpa.migrate.dao.HapiMigrationDao;
import ca.uhn.fhir.jpa.migrate.tasks.HapiFhirJpaMigrationTasks; import ca.uhn.fhir.jpa.migrate.tasks.HapiFhirJpaMigrationTasks;
import ca.uhn.fhir.jpa.provider.DiffProvider;
import ca.uhn.fhir.jpa.provider.JpaCapabilityStatementProvider;
import ca.uhn.fhir.jpa.provider.ProcessMessageProvider;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider;
import ca.uhn.fhir.jpa.provider.ValueSetOperationProvider;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.test.BaseJpaTest; import ca.uhn.fhir.jpa.test.BaseJpaTest;
import ca.uhn.fhir.jpa.test.config.TestR5Config; import ca.uhn.fhir.jpa.test.config.TestR5Config;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails; import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor;
import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory; import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory;
import ca.uhn.fhir.test.utilities.ITestDataBuilder; import ca.uhn.fhir.test.utilities.ITestDataBuilder;
import ca.uhn.fhir.test.utilities.server.RestfulServerConfigurerExtension; import ca.uhn.fhir.test.utilities.server.RestfulServerConfigurerExtension;
@ -30,6 +44,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r5.model.Bundle; import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.IdType; import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.IntegerType;
import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.Patient; import org.hl7.fhir.r5.model.Patient;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -40,6 +55,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean; import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean;
@ -47,8 +63,10 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.cors.CorsConfiguration;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -62,7 +80,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class) @EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@ContextConfiguration(classes = {BaseDatabaseVerificationIT.TestConfig.class, TestDaoSearch.Config.class}) @ContextConfiguration(classes = {BaseDatabaseVerificationIT.TestConfig.class})
public abstract class BaseDatabaseVerificationIT extends BaseJpaTest implements ITestDataBuilder { public abstract class BaseDatabaseVerificationIT extends BaseJpaTest implements ITestDataBuilder {
private static final Logger ourLog = LoggerFactory.getLogger(BaseDatabaseVerificationIT.class); private static final Logger ourLog = LoggerFactory.getLogger(BaseDatabaseVerificationIT.class);
private static final String MIGRATION_TABLENAME = "MIGRATIONS"; private static final String MIGRATION_TABLENAME = "MIGRATIONS";
@ -91,9 +109,6 @@ public abstract class BaseDatabaseVerificationIT extends BaseJpaTest implements
@Autowired @Autowired
private DatabaseBackedPagingProvider myPagingProvider; private DatabaseBackedPagingProvider myPagingProvider;
@Autowired
TestDaoSearch myTestDaoSearch;
@RegisterExtension @RegisterExtension
protected RestfulServerExtension myServer = new RestfulServerExtension(FhirContext.forR5Cached()); protected RestfulServerExtension myServer = new RestfulServerExtension(FhirContext.forR5Cached());
@ -160,20 +175,6 @@ public abstract class BaseDatabaseVerificationIT extends BaseJpaTest implements
assertThat(values.toString(), values, containsInAnyOrder(expectedIds.toArray(new String[0]))); assertThat(values.toString(), values, containsInAnyOrder(expectedIds.toArray(new String[0])));
} }
@Test
void testChainedSort() {
// given
// when
SearchParameterMap map = SearchParameterMap
.newSynchronous()
.setSort(new SortSpec("Practitioner:general-practitioner.family"));
myCaptureQueriesListener.clear();
myPatientDao.search(map, mySrd);
}
@Configuration @Configuration
@ -221,8 +222,8 @@ public abstract class BaseDatabaseVerificationIT extends BaseJpaTest implements
} }
public static class JpaDatabaseContextConfigParamObject { public static class JpaDatabaseContextConfigParamObject {
final JpaEmbeddedDatabase myJpaEmbeddedDatabase; private JpaEmbeddedDatabase myJpaEmbeddedDatabase;
final String myDialect; private String myDialect;
public JpaDatabaseContextConfigParamObject(JpaEmbeddedDatabase theJpaEmbeddedDatabase, String theDialect) { public JpaDatabaseContextConfigParamObject(JpaEmbeddedDatabase theJpaEmbeddedDatabase, String theDialect) {
myJpaEmbeddedDatabase = theJpaEmbeddedDatabase; myJpaEmbeddedDatabase = theJpaEmbeddedDatabase;

View File

@ -1,57 +0,0 @@
package ca.uhn.fhir.jpa.term;
import ca.uhn.fhir.jpa.dao.data.ITermConceptDao;
import ca.uhn.fhir.jpa.entity.TermConcept;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class TermConceptDaoSvcTest {
@Mock
private ITermConceptDao myConceptDao;
@InjectMocks
private TermConceptDaoSvc myTermConceptDaoSvc;
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testSaveConcept_withSupportLegacyLob(boolean theSupportLegacyLob){
final String parentPids = "1 2 3 4 5 6 7 8 9";
when(myConceptDao.save(any())).thenAnswer(t ->{
TermConcept codeSystem = (TermConcept) t.getArguments()[0];
codeSystem.prePersist();
return codeSystem;
});
ArgumentCaptor<TermConcept> captor = ArgumentCaptor.forClass(TermConcept.class);
// given
TermConcept termConcept = new TermConcept().setParentPids(parentPids);
// when
myTermConceptDaoSvc.setSupportLegacyLob(theSupportLegacyLob);
myTermConceptDaoSvc.saveConcept(termConcept);
// then
verify(myConceptDao, times(1)).save(captor.capture());
TermConcept capturedTermConcept = captor.getValue();
assertThat(capturedTermConcept.hasParentPidsLobForTesting(), equalTo(theSupportLegacyLob));
assertThat(capturedTermConcept.getParentPidsAsString(), equalTo(parentPids));
}
}

View File

@ -9,16 +9,11 @@ import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Optional; import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@ -79,22 +74,4 @@ public class ValueSetConceptAccumulatorTest {
} }
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testPersistValueSetConcept_whenSupportLegacyLob(boolean theSupportLegacyLob){
final String sourceConceptDirectParentPids = "1 2 3 4 5 6 7";
ArgumentCaptor<TermValueSetConcept> captor = ArgumentCaptor.forClass(TermValueSetConcept.class);
myAccumulator.setSupportLegacyLob(theSupportLegacyLob);
myAccumulator.includeConcept("sys", "code", "display", null, sourceConceptDirectParentPids, null);
verify(myValueSetConceptDao, times(1)).save(captor.capture());
TermValueSetConcept capturedTermValueSetConcept = captor.getValue();
assertThat(capturedTermValueSetConcept.hasSourceConceptDirectParentPidsLob(), equalTo(theSupportLegacyLob));
assertThat(capturedTermValueSetConcept.getSourceConceptDirectParentPids(), equalTo(sourceConceptDirectParentPids));
}
} }

View File

@ -31,22 +31,17 @@ import ca.uhn.fhir.mdm.api.params.MdmQuerySearchParameters;
import ca.uhn.fhir.mdm.model.MdmTransactionContext; import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import ca.uhn.fhir.mdm.model.mdmevents.MdmLinkJson; import ca.uhn.fhir.mdm.model.mdmevents.MdmLinkJson;
import ca.uhn.fhir.mdm.util.GoldenResourceHelper; import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails; import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import ca.uhn.fhir.util.TerserUtil; import ca.uhn.fhir.util.TerserUtil;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
public class MdmSurvivorshipSvcImpl implements IMdmSurvivorshipService { public class MdmSurvivorshipSvcImpl implements IMdmSurvivorshipService {
private static final Pattern IS_UUID =
Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
protected final FhirContext myFhirContext; protected final FhirContext myFhirContext;
@ -138,30 +133,16 @@ public class MdmSurvivorshipSvcImpl implements IMdmSurvivorshipService {
String sourceId = link.getSourceId(); String sourceId = link.getSourceId();
// +1 because of "/" in id: "ResourceType/Id" // +1 because of "/" in id: "ResourceType/Id"
final String sourceIdUnqualified = sourceId.substring(resourceType.length() + 1); IResourcePersistentId<?> pid = getResourcePID(sourceId.substring(resourceType.length() + 1), resourceType);
// myMdmLinkQuerySvc.queryLinks populates sourceId with the FHIR_ID, not the RES_ID, so if we don't // this might be a bit unperformant
// add this conditional logic, on JPA, myIIdHelperService.newPidFromStringIdAndResourceName will fail with // but it depends how many links there are
// NumberFormatException // per golden resource (unlikely to be thousands)
if (isNumericOrUuid(sourceIdUnqualified)) { return dao.readByPid(pid);
IResourcePersistentId<?> pid = getResourcePID(sourceIdUnqualified, resourceType);
// this might be a bit unperformant
// but it depends how many links there are
// per golden resource (unlikely to be thousands)
return dao.readByPid(pid);
} else {
return dao.read(new IdDt(sourceId), new SystemRequestDetails());
}
}); });
} }
private IResourcePersistentId<?> getResourcePID(String theId, String theResourceType) { private IResourcePersistentId<?> getResourcePID(String theId, String theResourceType) {
return myIIdHelperService.newPidFromStringIdAndResourceName(theId, theResourceType); return myIIdHelperService.newPidFromStringIdAndResourceName(theId, theResourceType);
} }
private boolean isNumericOrUuid(String theLongCandidate) {
return StringUtils.isNumeric(theLongCandidate)
|| IS_UUID.matcher(theLongCandidate).matches();
}
} }

View File

@ -22,8 +22,6 @@ package ca.uhn.fhir.rest.server.interceptor.auth;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import java.util.Collection;
public interface IAuthRuleBuilderOperationNamed { public interface IAuthRuleBuilderOperationNamed {
/** /**
@ -46,8 +44,6 @@ public interface IAuthRuleBuilderOperationNamed {
*/ */
IAuthRuleBuilderOperationNamedAndScoped onInstance(IIdType theInstanceId); IAuthRuleBuilderOperationNamedAndScoped onInstance(IIdType theInstanceId);
IAuthRuleBuilderOperationNamedAndScoped onInstances(Collection<IIdType> theInstanceIds);
/** /**
* Rule applies to invocations of this operation at the <code>instance</code> level on any instance of the given type * Rule applies to invocations of this operation at the <code>instance</code> level on any instance of the given type
*/ */

View File

@ -22,9 +22,6 @@ package ca.uhn.fhir.rest.server.interceptor.auth;
import jakarta.annotation.Nonnull; import jakarta.annotation.Nonnull;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import java.util.Collection;
import java.util.stream.Collectors;
/** /**
* @since 5.5.0 * @since 5.5.0
*/ */
@ -57,20 +54,10 @@ public interface IAuthRuleBuilderRuleBulkExport {
IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatient(@Nonnull String theFocusResourceId); IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatient(@Nonnull String theFocusResourceId);
IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnAllPatients();
default IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatient(@Nonnull IIdType theFocusResourceId) { default IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatient(@Nonnull IIdType theFocusResourceId) {
return patientExportOnPatient(theFocusResourceId.getValue()); return patientExportOnPatient(theFocusResourceId.getValue());
} }
default IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatients(
@Nonnull Collection<IIdType> theFocusResourceIds) {
return patientExportOnPatientStrings(
theFocusResourceIds.stream().map(IIdType::getValue).collect(Collectors.toList()));
}
IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatientStrings(Collection<String> theFocusResourceIds);
/** /**
* Allow/deny <b>patient-level</b> export rule applies to the Group with the given resource ID, e.g. <code>Group/123</code> * Allow/deny <b>patient-level</b> export rule applies to the Group with the given resource ID, e.g. <code>Group/123</code>
* *

View File

@ -736,20 +736,6 @@ public class RuleBuilder implements IAuthRuleBuilder {
return new RuleBuilderOperationNamedAndScoped(rule); return new RuleBuilderOperationNamedAndScoped(rule);
} }
@Override
public IAuthRuleBuilderOperationNamedAndScoped onInstances(Collection<IIdType> theInstanceIds) {
Validate.notNull(theInstanceIds, "theInstanceIds must not be null");
theInstanceIds.forEach(instanceId -> Validate.notBlank(
instanceId.getResourceType(),
"at least one of theInstanceIds does not have a resource type"));
theInstanceIds.forEach(instanceId -> Validate.notBlank(
instanceId.getIdPart(), "at least one of theInstanceIds does not have an ID part"));
final OperationRule rule = createRule();
rule.appliesToInstances(new ArrayList<>(theInstanceIds));
return new RuleBuilderOperationNamedAndScoped(rule);
}
@Override @Override
public IAuthRuleBuilderOperationNamedAndScoped onInstancesOfType( public IAuthRuleBuilderOperationNamedAndScoped onInstancesOfType(
Class<? extends IBaseResource> theType) { Class<? extends IBaseResource> theType) {
@ -883,7 +869,7 @@ public class RuleBuilder implements IAuthRuleBuilder {
} }
private class RuleBuilderBulkExport implements IAuthRuleBuilderRuleBulkExport { private class RuleBuilderBulkExport implements IAuthRuleBuilderRuleBulkExport {
private RuleBulkExportImpl myRuleBulkExport; private RuleBulkExportImpl ruleBulkExport;
@Override @Override
public IAuthRuleBuilderRuleBulkExportWithTarget groupExportOnGroup(@Nonnull String theFocusResourceId) { public IAuthRuleBuilderRuleBulkExportWithTarget groupExportOnGroup(@Nonnull String theFocusResourceId) {
@ -895,60 +881,23 @@ public class RuleBuilder implements IAuthRuleBuilder {
return new RuleBuilderBulkExportWithTarget(rule); return new RuleBuilderBulkExportWithTarget(rule);
} }
@Override
public IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnAllPatients() {
if (myRuleBulkExport == null) {
RuleBulkExportImpl rule = new RuleBulkExportImpl(myRuleName);
rule.setMode(myRuleMode);
myRuleBulkExport = rule;
}
myRuleBulkExport.setAppliesToPatientExportAllPatients();
// prevent duplicate rules being added
if (!myRules.contains(myRuleBulkExport)) {
myRules.add(myRuleBulkExport);
}
return new RuleBuilderBulkExportWithTarget(myRuleBulkExport);
}
@Override @Override
public IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatient(@Nonnull String theFocusResourceId) { public IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatient(@Nonnull String theFocusResourceId) {
if (myRuleBulkExport == null) { if (ruleBulkExport == null) {
RuleBulkExportImpl rule = new RuleBulkExportImpl(myRuleName); RuleBulkExportImpl rule = new RuleBulkExportImpl(myRuleName);
rule.setAppliesToPatientExport(theFocusResourceId); rule.setAppliesToPatientExport(theFocusResourceId);
rule.setMode(myRuleMode); rule.setMode(myRuleMode);
myRuleBulkExport = rule; ruleBulkExport = rule;
} else { } else {
myRuleBulkExport.setAppliesToPatientExport(theFocusResourceId); ruleBulkExport.setAppliesToPatientExport(theFocusResourceId);
} }
// prevent duplicate rules being added // prevent duplicate rules being added
if (!myRules.contains(myRuleBulkExport)) { if (!myRules.contains(ruleBulkExport)) {
myRules.add(myRuleBulkExport); myRules.add(ruleBulkExport);
} }
return new RuleBuilderBulkExportWithTarget(myRuleBulkExport); return new RuleBuilderBulkExportWithTarget(ruleBulkExport);
}
@Override
public IAuthRuleBuilderRuleBulkExportWithTarget patientExportOnPatientStrings(
@Nonnull Collection<String> theFocusResourceIds) {
if (myRuleBulkExport == null) {
RuleBulkExportImpl rule = new RuleBulkExportImpl(myRuleName);
rule.setAppliesToPatientExport(theFocusResourceIds);
rule.setMode(myRuleMode);
myRuleBulkExport = rule;
} else {
myRuleBulkExport.setAppliesToPatientExport(theFocusResourceIds);
}
// prevent duplicate rules being added
if (!myRules.contains(myRuleBulkExport)) {
myRules.add(myRuleBulkExport);
}
return new RuleBuilderBulkExportWithTarget(myRuleBulkExport);
} }
@Override @Override

View File

@ -24,12 +24,12 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.bulk.BulkExportJobParameters; import ca.uhn.fhir.rest.api.server.bulk.BulkExportJobParameters;
import com.google.common.annotations.VisibleForTesting;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -42,7 +42,6 @@ public class RuleBulkExportImpl extends BaseRule {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuleBulkExportImpl.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuleBulkExportImpl.class);
private String myGroupId; private String myGroupId;
private final Collection<String> myPatientIds; private final Collection<String> myPatientIds;
private boolean myAppliesToAllPatients;
private BulkExportJobParameters.ExportStyle myWantExportStyle; private BulkExportJobParameters.ExportStyle myWantExportStyle;
private Collection<String> myResourceTypes; private Collection<String> myResourceTypes;
private boolean myWantAnyStyle; private boolean myWantAnyStyle;
@ -70,84 +69,113 @@ public class RuleBulkExportImpl extends BaseRule {
return null; return null;
} }
BulkExportJobParameters inboundBulkExportRequestOptions = (BulkExportJobParameters) BulkExportJobParameters options = (BulkExportJobParameters)
theRequestDetails.getAttribute(AuthorizationInterceptor.REQUEST_ATTRIBUTE_BULK_DATA_EXPORT_OPTIONS); theRequestDetails.getAttribute(AuthorizationInterceptor.REQUEST_ATTRIBUTE_BULK_DATA_EXPORT_OPTIONS);
// if style doesn't match - abstain
if (!myWantAnyStyle && inboundBulkExportRequestOptions.getExportStyle() != myWantExportStyle) { if (!myWantAnyStyle && options.getExportStyle() != myWantExportStyle) {
return null; return null;
} }
// Do we only authorize some types? If so, make sure requested types are a subset
if (isNotEmpty(myResourceTypes)) { if (isNotEmpty(myResourceTypes)) {
if (isEmpty(inboundBulkExportRequestOptions.getResourceTypes())) { if (isEmpty(options.getResourceTypes())) {
return new AuthorizationInterceptor.Verdict(PolicyEnum.DENY, this);
}
if (!myResourceTypes.containsAll(inboundBulkExportRequestOptions.getResourceTypes())) {
return new AuthorizationInterceptor.Verdict(PolicyEnum.DENY, this);
}
}
// system only supports filtering by resource type. So if we are system, or any(), then allow, since we have
// done resource type checking
// above
AuthorizationInterceptor.Verdict allowVerdict = newVerdict(
theOperation,
theRequestDetails,
theInputResource,
theInputResourceId,
theOutputResource,
theRuleApplier);
if (myWantAnyStyle || myWantExportStyle == BulkExportJobParameters.ExportStyle.SYSTEM) {
return allowVerdict;
}
// assume myGroupId not empty->myStyle is group. If target group matches, then allow.
if (isNotBlank(myGroupId) && inboundBulkExportRequestOptions.getGroupId() != null) {
String expectedGroupId =
new IdDt(myGroupId).toUnqualifiedVersionless().getValue();
String actualGroupId = new IdDt(inboundBulkExportRequestOptions.getGroupId())
.toUnqualifiedVersionless()
.getValue();
if (Objects.equals(expectedGroupId, actualGroupId)) {
return allowVerdict;
}
}
// patient export mode - instance or type. type can have 0..n patient ids.
// myPatientIds == the rules built by the auth interceptor rule builder
// options.getPatientIds() == the requested IDs in the export job.
// 1. If each of the requested resource IDs in the parameters are present in the users permissions, Approve
// 2. If any requested ID is not present in the users permissions, Deny.
if (myWantExportStyle == BulkExportJobParameters.ExportStyle.PATIENT)
// Unfiltered Type Level
if (myAppliesToAllPatients) {
return allowVerdict;
}
// Instance level, or filtered type level
if (isNotEmpty(myPatientIds)) {
// If bulk export options defines no patient IDs, return null.
if (inboundBulkExportRequestOptions.getPatientIds().isEmpty()) {
return null; return null;
} else { }
ourLog.debug("options.getPatientIds() != null"); for (String next : options.getResourceTypes()) {
Set<String> requestedPatientIds = sanitizeIds(inboundBulkExportRequestOptions.getPatientIds()); if (!myResourceTypes.contains(next)) {
Set<String> permittedPatientIds = sanitizeIds(myPatientIds);
if (permittedPatientIds.containsAll(requestedPatientIds)) {
return allowVerdict;
} else {
return new AuthorizationInterceptor.Verdict(PolicyEnum.DENY, this); return new AuthorizationInterceptor.Verdict(PolicyEnum.DENY, this);
} }
} }
} }
return null;
}
private Set<String> sanitizeIds(Collection<String> myPatientIds) { if (myWantAnyStyle || myWantExportStyle == BulkExportJobParameters.ExportStyle.SYSTEM) {
return myPatientIds.stream() return newVerdict(
.map(id -> new IdDt(id).toUnqualifiedVersionless().getValue()) theOperation,
.collect(Collectors.toSet()); theRequestDetails,
theInputResource,
theInputResourceId,
theOutputResource,
theRuleApplier);
}
if (isNotBlank(myGroupId) && options.getGroupId() != null) {
String expectedGroupId =
new IdDt(myGroupId).toUnqualifiedVersionless().getValue();
String actualGroupId =
new IdDt(options.getGroupId()).toUnqualifiedVersionless().getValue();
if (Objects.equals(expectedGroupId, actualGroupId)) {
return newVerdict(
theOperation,
theRequestDetails,
theInputResource,
theInputResourceId,
theOutputResource,
theRuleApplier);
}
}
// 1. If each of the requested resource IDs in the parameters are present in the users permissions, Approve
// 2. If any requested ID is not present in the users permissions, Deny.
if (myWantExportStyle == BulkExportJobParameters.ExportStyle.PATIENT && isNotEmpty(myPatientIds)) {
List<String> permittedPatientIds = myPatientIds.stream()
.map(id -> new IdDt(id).toUnqualifiedVersionless().getValue())
.collect(Collectors.toList());
if (!options.getPatientIds().isEmpty()) {
ourLog.debug("options.getPatientIds() != null");
List<String> requestedPatientIds = options.getPatientIds().stream()
.map(t -> new IdDt(t).toUnqualifiedVersionless().getValue())
.collect(Collectors.toList());
boolean requestedPatientsPermitted = true;
for (String requestedPatientId : requestedPatientIds) {
if (!permittedPatientIds.contains(requestedPatientId)) {
requestedPatientsPermitted = false;
break;
}
}
if (requestedPatientsPermitted) {
return newVerdict(
theOperation,
theRequestDetails,
theInputResource,
theInputResourceId,
theOutputResource,
theRuleApplier);
}
return new AuthorizationInterceptor.Verdict(PolicyEnum.DENY, this);
}
final List<String> filters = options.getFilters();
if (!filters.isEmpty()) {
ourLog.debug("filters not empty");
final Set<String> patientIdsInFilters = filters.stream()
.filter(filter -> filter.startsWith("Patient?_id="))
.map(filter -> filter.replace("?_id=", "/"))
.collect(Collectors.toUnmodifiableSet());
boolean filteredPatientIdsPermitted = true;
for (String patientIdInFilters : patientIdsInFilters) {
if (!permittedPatientIds.contains(patientIdInFilters)) {
filteredPatientIdsPermitted = false;
break;
}
}
if (filteredPatientIdsPermitted) {
return newVerdict(
theOperation,
theRequestDetails,
theInputResource,
theInputResourceId,
theOutputResource,
theRuleApplier);
}
return new AuthorizationInterceptor.Verdict(PolicyEnum.DENY, this);
}
ourLog.debug("patientIds and filters both empty");
}
return null;
} }
public void setAppliesToGroupExportOnGroup(String theGroupId) { public void setAppliesToGroupExportOnGroup(String theGroupId) {
@ -165,16 +193,6 @@ public class RuleBulkExportImpl extends BaseRule {
myPatientIds.add(thePatientId); myPatientIds.add(thePatientId);
} }
public void setAppliesToPatientExport(Collection<String> thePatientIds) {
myWantExportStyle = BulkExportJobParameters.ExportStyle.PATIENT;
myPatientIds.addAll(thePatientIds);
}
public void setAppliesToPatientExportAllPatients() {
myWantExportStyle = BulkExportJobParameters.ExportStyle.PATIENT;
myAppliesToAllPatients = true;
}
public void setAppliesToSystem() { public void setAppliesToSystem() {
myWantExportStyle = BulkExportJobParameters.ExportStyle.SYSTEM; myWantExportStyle = BulkExportJobParameters.ExportStyle.SYSTEM;
} }
@ -194,14 +212,4 @@ public class RuleBulkExportImpl extends BaseRule {
BulkExportJobParameters.ExportStyle getWantExportStyle() { BulkExportJobParameters.ExportStyle getWantExportStyle() {
return myWantExportStyle; return myWantExportStyle;
} }
@VisibleForTesting
Collection<String> getPatientIds() {
return myPatientIds;
}
@VisibleForTesting
Collection<String> getResourceTypes() {
return myResourceTypes;
}
} }

View File

@ -1,23 +1,16 @@
package ca.uhn.fhir.rest.server.interceptor.auth; package ca.uhn.fhir.rest.server.interceptor.auth;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class RuleBuilderTest { public class RuleBuilderTest {
@ -105,72 +98,7 @@ public class RuleBuilderTest {
builder.allow().bulkExport().patientExportOnPatient("Patient/pat2").withResourceTypes(resourceTypes); builder.allow().bulkExport().patientExportOnPatient("Patient/pat2").withResourceTypes(resourceTypes);
List<IAuthRule> rules = builder.build(); List<IAuthRule> rules = builder.build();
assertEquals(rules.size(),1); assertEquals(rules.size(),1);
assertInstanceOf(RuleBulkExportImpl.class, rules.get(0)); assertTrue(rules.get(0) instanceof RuleBulkExportImpl);
}
public static Stream<Arguments> multipleInstancesParams() {
return Stream.of(
Arguments.of(List.of("Patient/pat1"), List.of("Patient"), PolicyEnum.ALLOW),
Arguments.of(List.of("Patient/pat1", "Patient/pat2"), List.of("Patient"), PolicyEnum.ALLOW),
Arguments.of(List.of("Patient/pat1", "Patient/pat2"), List.of("Patient", "Observation"), PolicyEnum.ALLOW),
Arguments.of(List.of("Patient/pat1"), List.of("Patient"), PolicyEnum.DENY),
Arguments.of(List.of("Patient/pat1", "Patient/pat2"), List.of("Patient"), PolicyEnum.DENY),
Arguments.of(List.of("Patient/pat1", "Patient/pat2"), List.of("Patient", "Observation"), PolicyEnum.DENY)
);
}
@ParameterizedTest
@MethodSource("multipleInstancesParams")
public void testBulkExport_PatientExportOnPatients_MultiplePatientsSingleRule(Collection<String> theExpectedPatientIds, Collection<String> theExpectedResourceTypes, PolicyEnum thePolicyEnum) {
final RuleBuilder builder = new RuleBuilder();
final IAuthRuleBuilderRule rule = switch (thePolicyEnum) {
case ALLOW -> builder.allow();
case DENY -> builder.deny();
};
rule.bulkExport().patientExportOnPatientStrings(theExpectedPatientIds).withResourceTypes(theExpectedResourceTypes);
final List<IAuthRule> rules = builder.build();
assertEquals(rules.size(),1);
final IAuthRule authRule = rules.get(0);
assertInstanceOf(RuleBulkExportImpl.class, authRule);
final RuleBulkExportImpl ruleBulkExport = (RuleBulkExportImpl) authRule;
assertEquals(theExpectedPatientIds, ruleBulkExport.getPatientIds());
assertEquals(theExpectedResourceTypes, ruleBulkExport.getResourceTypes());
assertEquals(thePolicyEnum, ruleBulkExport.getMode());
}
public static Stream<Arguments> owners() {
return Stream.of(
Arguments.of(List.of(new IdDt("Patient/pat1")), PolicyEnum.ALLOW),
Arguments.of(List.of(new IdDt("Patient/pat1")), PolicyEnum.DENY),
Arguments.of(List.of(new IdDt("Patient/pat1"), new IdDt("Patient/pat2")), PolicyEnum.ALLOW),
Arguments.of(List.of(new IdDt("Patient/pat1"), new IdDt("Patient/pat2")), PolicyEnum.DENY)
);
}
@ParameterizedTest
@MethodSource("owners")
public void testBulkExport_PatientExportOnPatients_onInstances(List<IIdType> theExpectedOwners, PolicyEnum thePolicyEnum) {
final RuleBuilder builder = new RuleBuilder();
final IAuthRuleBuilderRule rule = switch (thePolicyEnum) {
case ALLOW -> builder.allow();
case DENY -> builder.deny();
};
final List<IAuthRule> rules = rule
.operation()
.named(ProviderConstants.OPERATION_EXPORT)
.onInstances(theExpectedOwners)
.andAllowAllResponses()
.andThen()
.build();
assertEquals(rules.size(),1);
final IAuthRule authRule = rules.get(0);
assertInstanceOf(OperationRule.class, authRule);
final OperationRule operationRule = (OperationRule) authRule;
assertEquals(theExpectedOwners, operationRule.getAppliesToIds());
assertEquals(ProviderConstants.OPERATION_EXPORT, operationRule.getOperationName());
assertEquals(thePolicyEnum, operationRule.getMode());
} }
@Test @Test

View File

@ -4,9 +4,6 @@ import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.bulk.BulkExportJobParameters; import ca.uhn.fhir.rest.api.server.bulk.BulkExportJobParameters;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
@ -16,6 +13,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -30,11 +28,10 @@ public class RuleBulkExportImplTest {
@Mock @Mock
private Set<AuthorizationFlagsEnum> myFlags; private Set<AuthorizationFlagsEnum> myFlags;
@Test @Test
public void testDenyBulkRequestWithInvalidResourcesTypes() { public void testDenyBulkRequestWithInvalidResourcesTypes() {
RuleBulkExportImpl myRule = new RuleBulkExportImpl("a"); RuleBulkExportImpl myRule = new RuleBulkExportImpl("a");
myRule.setMode(PolicyEnum.ALLOW);
Set<String> myTypes = new HashSet<>(); Set<String> myTypes = new HashSet<>();
myTypes.add("Patient"); myTypes.add("Patient");
myTypes.add("Practitioner"); myTypes.add("Practitioner");
@ -49,206 +46,29 @@ public class RuleBulkExportImplTest {
when(myRequestDetails.getAttribute(any())).thenReturn(options); when(myRequestDetails.getAttribute(any())).thenReturn(options);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertDeny(verdict); assertEquals(PolicyEnum.DENY, verdict.getDecision());
} }
@Test @Test
public void test_RuleSpecifiesResourceTypes_RequestDoesNot_Abstains() { public void testBulkRequestWithValidResourcesTypes() {
RuleBulkExportImpl myRule = new RuleBulkExportImpl("a"); RuleBulkExportImpl myRule = new RuleBulkExportImpl("a");
myRule.setAppliesToPatientExportAllPatients();
myRule.setMode(PolicyEnum.ALLOW);
Set<String> myTypes = new HashSet<>(); Set<String> myTypes = new HashSet<>();
myTypes.add("Patient"); myTypes.add("Patient");
myTypes.add("Practitioner");
myRule.setResourceTypes(myTypes); myRule.setResourceTypes(myTypes);
Set<String> myWantTypes = new HashSet<>();
myWantTypes.add("Patient");
myWantTypes.add("Practitioner");
BulkExportJobParameters options = new BulkExportJobParameters(); BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT); options.setResourceTypes(myWantTypes);
when(myRequestDetails.getAttribute(any())).thenReturn(options);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertDeny(verdict);
}
@Test
public void testBulkExportSystem_ruleHasTypes_RequestWithTypes_allow() {
RuleBulkExportImpl myRule = new RuleBulkExportImpl("a");
myRule.setMode(PolicyEnum.ALLOW);
myRule.setAppliesToSystem();
myRule.setResourceTypes(Set.of("Patient", "Practitioner"));
BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.SYSTEM);
options.setResourceTypes(Set.of("Patient", "Practitioner"));
when(myRequestDetails.getAttribute(any())).thenReturn(options); when(myRequestDetails.getAttribute(any())).thenReturn(options);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertNull(verdict);
assertAllow(verdict);
}
@Test
public void testBulkExportSystem_ruleHasTypes_RequestWithTooManyTypes_abstain() {
RuleBulkExportImpl myRule = new RuleBulkExportImpl("a");
myRule.setMode(PolicyEnum.ALLOW);
myRule.setAppliesToSystem();
myRule.setResourceTypes(Set.of("Patient", "Practitioner"));
BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.SYSTEM);
options.setResourceTypes(Set.of("Patient", "Practitioner", "Encounter"));
when(myRequestDetails.getAttribute(any())).thenReturn(options);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertDeny(verdict);
}
@Nested
class StyleChecks {
BulkExportJobParameters myOptions = new BulkExportJobParameters();
RuleBulkExportImpl myRule = new RuleBulkExportImpl("a");
@BeforeEach
void setUp() {
myRule.setMode(PolicyEnum.ALLOW);
when(myRequestDetails.getAttribute(any())).thenReturn(myOptions);
}
@Nested class RuleAnyStyle {
@BeforeEach
void setUp(){
myRule.setAppliesToAny();
}
@Test
public void testRuleAnyStyle_Matches_SystemStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.SYSTEM);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
@Test
public void testRuleAnyStyle_Matches_PatientStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
@Test
public void testRuleAnyStyle_Matches_GroupStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.GROUP);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
}
@Nested
class RuleSystemStyle {
@BeforeEach
void setUp() {
myRule.setAppliesToSystem();
}
@Test
public void test_Matches_SystemStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.SYSTEM);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
@Test
public void test_DoesntMatch_GroupStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.GROUP);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict);
}
@Test
public void test_DoesntMatch_PatientStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict);
}
}
@Nested
class RuleGroupStyle {
@BeforeEach
void setUp() {
myRule.setAppliesToGroupExportOnGroup("Group/123");
}
@Test
public void test_DoesntMatch_SystemStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.SYSTEM);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict);
}
@Test
public void test_Matches_GroupStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.GROUP);
myOptions.setGroupId("Group/123");
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
@Test
public void test_DoesntMatch_PatientStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict);
}
}
@Nested
class RulePatientStyle {
@BeforeEach
void setUp() {
myRule.setAppliesToPatientExport("Patient/123");
}
@Test
public void test_DoesntMatch_SystemStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.SYSTEM);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict);
}
@Test
public void test_DoesntMatch_GroupStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.GROUP);
myOptions.setGroupId("Group/123");
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict);
}
@Test
public void test_DoesntMatch_PatientStyle() {
myOptions.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
myOptions.setPatientIds(Set.of("Patient/123"));
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
}
} }
@Test @Test
@ -264,7 +84,7 @@ public class RuleBulkExportImplTest {
when(myRequestDetails.getAttribute(any())).thenReturn(options); when(myRequestDetails.getAttribute(any())).thenReturn(options);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAbstain(verdict); assertEquals(null, verdict);
} }
@Test @Test
@ -280,7 +100,7 @@ public class RuleBulkExportImplTest {
when(myRequestDetails.getAttribute(any())).thenReturn(options); when(myRequestDetails.getAttribute(any())).thenReturn(options);
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict); assertEquals(PolicyEnum.ALLOW, verdict.getDecision());
} }
@Test @Test
@ -298,7 +118,7 @@ public class RuleBulkExportImplTest {
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: We permit the request, as a patient ID that was requested is honoured by this rule. //Then: We permit the request, as a patient ID that was requested is honoured by this rule.
assertAllow(verdict); assertEquals(PolicyEnum.ALLOW, verdict.getDecision());
} }
@Test @Test
@ -315,8 +135,8 @@ public class RuleBulkExportImplTest {
//When //When
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: abstain //Then: we should deny the request, as the requested export does not contain the patient permitted.
assertDeny(verdict); assertEquals(PolicyEnum.DENY, verdict.getDecision());
} }
@Test @Test
@ -333,45 +153,28 @@ public class RuleBulkExportImplTest {
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: We make no claims about type-level export on Patient. //Then: We make no claims about type-level export on Patient.
assertAbstain(verdict); assertEquals(null, verdict);
} }
@Test @Test
public void testPatientExportRulesWithId_withRequestNoIds_abstains() { public void testPatientExportRulesOnTypeLevelExportWithTypeFilterResourceTypePatient() {
//Given //Given
RuleBulkExportImpl myRule = new RuleBulkExportImpl("b"); final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123"); myRule.setAppliesToPatientExport("Patient/123");
myRule.setMode(PolicyEnum.ALLOW); myRule.setMode(PolicyEnum.ALLOW);
BulkExportJobParameters options = new BulkExportJobParameters(); final BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT); options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
options.setFilters(Set.of("Patient?_id=123"));
options.setResourceTypes(Set.of("Patient"));
when(myRequestDetails.getAttribute(any())).thenReturn(options); when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When //When
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: We make no claims about type-level export on Patient. //Then: The patient IDs match so this is permitted
assertAbstain(verdict); assertEquals(PolicyEnum.ALLOW, verdict.getDecision());
} }
@Test
public void testPatientExportRuleWithNoIds_withRequestNoIds_allows() {
//Given
RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExportAllPatients();
myRule.setMode(PolicyEnum.ALLOW);
BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When
AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
assertAllow(verdict);
}
@Test @Test
public void testPatientExportRulesOnTypeLevelExportWithTypeFilterResourceTypePatientAndFilterHasResources() { public void testPatientExportRulesOnTypeLevelExportWithTypeFilterResourceTypePatientAndFilterHasResources() {
//Given //Given
@ -388,9 +191,27 @@ public class RuleBulkExportImplTest {
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: The patient IDs match so this is permitted //Then: The patient IDs match so this is permitted
assertAbstain(verdict); assertEquals(PolicyEnum.ALLOW, verdict.getDecision());
} }
@Test
public void testPatientExportRulesOnTypeLevelExportWithTypeFilterResourceTypeObservation() {
//Given
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123");
myRule.setMode(PolicyEnum.ALLOW);
final BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
options.setFilters(Set.of("Patient?_id=123"));
options.setResourceTypes(Set.of("Observation"));
when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: The patient IDs match so this is permitted
assertEquals(PolicyEnum.ALLOW, verdict.getDecision());
}
@Test @Test
public void testPatientExportRulesOnTypeLevelExportWithTypeFilterNoResourceType() { public void testPatientExportRulesOnTypeLevelExportWithTypeFilterNoResourceType() {
@ -406,8 +227,27 @@ public class RuleBulkExportImplTest {
//When //When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: Filters are ignored for auth purposes. The rule has an ID, indicating it is for instance level, but the job requested type level. Abstain //Then: The patient IDs match so this is permitted
assertAbstain(verdict); assertEquals(PolicyEnum.ALLOW, verdict.getDecision());
}
@Test
public void testPatientExportRulesOnTypeLevelExportWithTypeFilterMismatch() {
//Given
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123");
myRule.setMode(PolicyEnum.ALLOW);
final BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
options.setFilters(Set.of("Patient?_id=456"));
options.setResourceTypes(Set.of("Patient"));
when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: The patient IDs do NOT match so this is not permitted.
assertEquals(PolicyEnum.DENY, verdict.getDecision());
} }
@Test @Test
@ -425,12 +265,12 @@ public class RuleBulkExportImplTest {
//When //When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: We do not have permissions on the requested patient so we abstain //Then: We do not have permissions on the requested patient so this is not permitted.
assertDeny(verdict); assertEquals(PolicyEnum.DENY, verdict.getDecision());
} }
@Test @Test
public void testPatientExport_ruleAllowsId_requestsId_allow() { public void testPatientExportRulesOnTypeLevelExportPermittedPatient() {
//Given //Given
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b"); final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123"); myRule.setAppliesToPatientExport("Patient/123");
@ -449,7 +289,7 @@ public class RuleBulkExportImplTest {
} }
@Test @Test
public void testPatientExport_ruleAllowsIds_requestsIds_allow() { public void testPatientExportRulesOnTypeLevelExportPermittedPatients() {
//Given //Given
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b"); final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123"); myRule.setAppliesToPatientExport("Patient/123");
@ -469,7 +309,7 @@ public class RuleBulkExportImplTest {
} }
@Test @Test
public void testPatientExport_ruleAllowsId_requestsTooManyIds_abstain() { public void testPatientExportRulesOnTypeLevelExportWithPermittedAndUnpermittedPatients() {
//Given //Given
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b"); final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123"); myRule.setAppliesToPatientExport("Patient/123");
@ -484,61 +324,8 @@ public class RuleBulkExportImplTest {
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: There are unpermitted patients in the request so this is not permitted. //Then: There are unpermitted patients in the request so this is not permitted.
assertDeny(verdict); assertEquals(PolicyEnum.DENY, verdict.getDecision());
} //
@Test
public void testPatientExport_RuleAllowsAll_RequestId_allows() {
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExportAllPatients();
myRule.setMode(PolicyEnum.ALLOW);
final BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
options.setPatientIds(Set.of("Patient/123"));
when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then
assertAllow(verdict);
} }
@Test
public void testPatientExport_RuleAllowsAll_RequestAll_allows() {
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExportAllPatients();
myRule.setMode(PolicyEnum.ALLOW);
final BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then
assertAllow(verdict);
}
@Test
public void testPatientExport_RuleAllowsExplicitPatient_RequestAll_abstain() {
final RuleBulkExportImpl myRule = new RuleBulkExportImpl("b");
myRule.setAppliesToPatientExport("Patient/123");
myRule.setMode(PolicyEnum.ALLOW);
final BulkExportJobParameters options = new BulkExportJobParameters();
options.setExportStyle(BulkExportJobParameters.ExportStyle.PATIENT);
when(myRequestDetails.getAttribute(any())).thenReturn(options);
//When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then
assertAbstain(verdict);
}
@Test @Test
public void testPatientExportRulesOnTypeLevelExportWithPermittedAndUnpermittedPatientFilters() { public void testPatientExportRulesOnTypeLevelExportWithPermittedAndUnpermittedPatientFilters() {
//Given //Given
@ -554,22 +341,7 @@ public class RuleBulkExportImplTest {
//When //When
final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut); final AuthorizationInterceptor.Verdict verdict = myRule.applyRule(myOperation, myRequestDetails, null, null, null, myRuleApplier, myFlags, myPointcut);
//Then: There are unpermitted patients in the request so this is not permitted. abstain. //Then: There are unpermitted patients in the request so this is not permitted.
assertAbstain(verdict); assertEquals(PolicyEnum.DENY, verdict.getDecision());
}
private static void assertAbstain(AuthorizationInterceptor.Verdict verdict) {
Assertions.assertEquals(null, verdict, "Expect abstain");
}
private static void assertAllow(AuthorizationInterceptor.Verdict verdict) {
Assertions.assertNotNull(verdict, "Expect ALLOW, got abstain");
Assertions.assertEquals(PolicyEnum.ALLOW, verdict.getDecision(), "Expect ALLOW");
}
private static void assertDeny(AuthorizationInterceptor.Verdict verdict) {
Assertions.assertNotNull(verdict, "Expect DENY, got abstain");
Assertions.assertEquals(PolicyEnum.DENY, verdict.getDecision(), "Expect DENY");
} }
} }

View File

@ -308,14 +308,6 @@ public abstract class BaseTask {
} }
} }
public void doNothing() {
setDoNothing(true);
}
public void failureAllowed() {
setFailureAllowed(true);
}
public boolean isDoNothing() { public boolean isDoNothing() {
return myDoNothing; return myDoNothing;
} }

View File

@ -22,8 +22,11 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.intellij.lang.annotations.Language;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Set; import java.util.Set;
@ -48,12 +51,53 @@ public class RenameTableTask extends BaseTableTask {
setDescription("Rename table " + getOldTableName()); setDescription("Rename table " + getOldTableName());
} }
private void handleTableWithNewTableName() throws SQLException {
if (!myDeleteTargetColumnFirstIfExist) {
throw new SQLException(Msg.code(2517) + "Can not rename " + getOldTableName() + " to " + getNewTableName()
+ " because a table with name " + getNewTableName() + " already exists");
}
// a table with the new tableName already exists and we can delete it. we will only do so if it is empty.
Integer rowsWithData = getConnectionProperties().getTxTemplate().execute(t -> {
String sql = "SELECT * FROM " + getNewTableName();
JdbcTemplate jdbcTemplate = getConnectionProperties().newJdbcTemplate();
jdbcTemplate.setMaxRows(1);
return jdbcTemplate.query(sql, new ColumnMapRowMapper()).size();
});
if (rowsWithData != null && rowsWithData > 0) {
throw new SQLException(Msg.code(2518) + "Can not rename " + getOldTableName() + " to " + getNewTableName()
+ " because a table with name " + getNewTableName() + " already exists and is populated.");
}
logInfo(
ourLog,
"Table {} already exists - Going to drop it before renaming table {} to {}",
getNewTableName(),
getOldTableName(),
getNewTableName());
@Language("SQL")
String sql = "DROP TABLE " + getNewTableName();
executeSql(getNewTableName(), sql);
}
@Override @Override
public void doExecute() throws SQLException { public void doExecute() throws SQLException {
Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties()); Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties());
boolean hasTableWithNewTableName = tableNames.contains(getNewTableName()); boolean hasTableWithNewTableName = tableNames.contains(getNewTableName());
if (!tableNames.contains(getOldTableName())) {
throw new SQLException(Msg.code(2516) + "Can not rename " + getOldTableName() + " to " + getNewTableName()
+ " because the original table does not exists");
}
if (hasTableWithNewTableName) {
handleTableWithNewTableName();
}
String sql = buildRenameTableSqlStatement(); String sql = buildRenameTableSqlStatement();
logInfo(ourLog, "Renaming table: {}", getOldTableName()); logInfo(ourLog, "Renaming table: {}", getOldTableName());

View File

@ -57,7 +57,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -186,7 +185,6 @@ public class Builder {
private final String myRelease; private final String myRelease;
private final BaseMigrationTasks.IAcceptsTasks mySink; private final BaseMigrationTasks.IAcceptsTasks mySink;
private final String myTableName; private final String myTableName;
private BaseTask myLastAddedTask;
public BuilderWithTableName(String theRelease, BaseMigrationTasks.IAcceptsTasks theSink, String theTableName) { public BuilderWithTableName(String theRelease, BaseMigrationTasks.IAcceptsTasks theSink, String theTableName) {
myRelease = theRelease; myRelease = theRelease;
@ -276,7 +274,6 @@ public class Builder {
@Override @Override
public void addTask(BaseTask theTask) { public void addTask(BaseTask theTask) {
((BaseTableTask) theTask).setTableName(myTableName); ((BaseTableTask) theTask).setTableName(myTableName);
myLastAddedTask = theTask;
mySink.addTask(theTask); mySink.addTask(theTask);
} }
@ -314,10 +311,6 @@ public class Builder {
return this; return this;
} }
public Optional<BaseTask> getLastAddedTask() {
return Optional.ofNullable(myLastAddedTask);
}
/** /**
* @param theFkName the name of the foreign key * @param theFkName the name of the foreign key
* @param theParentTableName the name of the table that exports the foreign key * @param theParentTableName the name of the table that exports the foreign key
@ -330,37 +323,31 @@ public class Builder {
addTask(task); addTask(task);
} }
public BuilderCompleteTask renameTable(String theVersion, String theNewTableName) { public void renameTable(String theVersion, String theNewTableName) {
RenameTableTask task = new RenameTableTask(myRelease, theVersion, getTableName(), theNewTableName); RenameTableTask task = new RenameTableTask(myRelease, theVersion, getTableName(), theNewTableName);
addTask(task); addTask(task);
return new BuilderCompleteTask(task);
} }
public BuilderCompleteTask migratePostgresTextClobToBinaryClob(String theVersion, String theColumnName) { public void migratePostgresTextClobToBinaryClob(String theVersion, String theColumnName) {
MigratePostgresTextClobToBinaryClobTask task = MigratePostgresTextClobToBinaryClobTask task =
new MigratePostgresTextClobToBinaryClobTask(myRelease, theVersion); new MigratePostgresTextClobToBinaryClobTask(myRelease, theVersion);
task.setTableName(getTableName()); task.setTableName(getTableName());
task.setColumnName(theColumnName); task.setColumnName(theColumnName);
addTask(task); addTask(task);
return new BuilderCompleteTask(task);
} }
public BuilderCompleteTask migrateBlobToBinary( public void migrateBlobToBinary(String theVersion, String theFromColumName, String theToColumName) {
String theVersion, String theFromColumName, String theToColumName) {
MigrateColumBlobTypeToBinaryTypeTask task = new MigrateColumBlobTypeToBinaryTypeTask( MigrateColumBlobTypeToBinaryTypeTask task = new MigrateColumBlobTypeToBinaryTypeTask(
myRelease, theVersion, getTableName(), theFromColumName, theToColumName); myRelease, theVersion, getTableName(), theFromColumName, theToColumName);
addTask(task); addTask(task);
return new BuilderCompleteTask(task);
} }
public BuilderCompleteTask migrateClobToText( public void migrateClobToText(String theVersion, String theFromColumName, String theToColumName) {
String theVersion, String theFromColumName, String theToColumName) {
MigrateColumnClobTypeToTextTypeTask task = new MigrateColumnClobTypeToTextTypeTask( MigrateColumnClobTypeToTextTypeTask task = new MigrateColumnClobTypeToTextTypeTask(
myRelease, theVersion, getTableName(), theFromColumName, theToColumName); myRelease, theVersion, getTableName(), theFromColumName, theToColumName);
addTask(task); addTask(task);
return new BuilderCompleteTask(task);
} }
public class BuilderAddIndexWithName { public class BuilderAddIndexWithName {

View File

@ -41,4 +41,26 @@ public class RenameTableTaskTest extends BaseTest {
assertThat(tableNames, not(hasItem(oldTableName))); assertThat(tableNames, not(hasItem(oldTableName)));
} }
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void testRenameTableTask_whenTableDoesNotExists_willRaiseException(Supplier<TestDatabaseDetails> theTestDatabaseDetails) throws SQLException {
// given
before(theTestDatabaseDetails);
final String newTableName = "NEWTABLE";
final String oldTableName = "SOMETABLE";
RenameTableTask task = new RenameTableTask("1", "1", oldTableName, newTableName);
getMigrator().addTask(task);
// when
try {
getMigrator().migrate();
fail();
} catch (Exception e){
// then
assertThat(e.getMessage(), containsString("2516"));
}
}
} }

View File

@ -436,16 +436,6 @@ public class BulkDataImportProviderTest {
public boolean isResourcePartitionable(String theResourceType) { public boolean isResourcePartitionable(String theResourceType) {
return false; return false;
} }
@Override
public RequestPartitionId validateAndNormalizePartitionIds(RequestPartitionId theRequestPartitionId) {
return null;
}
@Override
public RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId theRequestPartitionId) {
return null;
}
} }
private Date parseDate(String theString) { private Date parseDate(String theString) {

View File

@ -1,22 +1,3 @@
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* 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%
*/
package ca.uhn.fhir.cr.r4; package ca.uhn.fhir.cr.r4;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;

View File

@ -1,22 +1,3 @@
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* 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%
*/
package ca.uhn.fhir.cr.r4; package ca.uhn.fhir.cr.r4;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;

View File

@ -1,22 +1,3 @@
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* 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%
*/
package ca.uhn.fhir.cr.r4.measure; package ca.uhn.fhir.cr.r4.measure;
import ca.uhn.fhir.cr.r4.ICollectDataServiceFactory; import ca.uhn.fhir.cr.r4.ICollectDataServiceFactory;

View File

@ -1,22 +1,3 @@
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* 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%
*/
package ca.uhn.fhir.cr.r4.measure; package ca.uhn.fhir.cr.r4.measure;
import ca.uhn.fhir.cr.r4.IDataRequirementsServiceFactory; import ca.uhn.fhir.cr.r4.IDataRequirementsServiceFactory;

View File

@ -102,9 +102,7 @@ public class DaoTestDataBuilder implements ITestDataBuilder.WithSupport, ITestDa
public void cleanup() { public void cleanup() {
ourLog.info("cleanup {}", myIds); ourLog.info("cleanup {}", myIds);
myIds.keySet().stream() myIds.keySet().forEach(nextType->{
.sorted() // Hack to ensure Patients are deleted before Practitioners. This may need to be refined.
.forEach(nextType->{
// todo do this in a bundle for perf. // todo do this in a bundle for perf.
IFhirResourceDao<?> dao = myDaoRegistry.getResourceDao(nextType); IFhirResourceDao<?> dao = myDaoRegistry.getResourceDao(nextType);
myIds.get(nextType).forEach(dao::delete); myIds.get(nextType).forEach(dao::delete);

View File

@ -360,14 +360,6 @@ public class JpaStorageSettings extends StorageSettings {
*/ */
private long myRestDeleteByUrlResourceIdThreshold = DEFAULT_REST_DELETE_BY_URL_RESOURCE_ID_THRESHOLD; private long myRestDeleteByUrlResourceIdThreshold = DEFAULT_REST_DELETE_BY_URL_RESOURCE_ID_THRESHOLD;
/**
* If enabled, this setting causes persisting data to legacy LOB columns as well as columns introduced
* to migrate away from LOB columns which effectively duplicates stored information.
*
* @since 7.2.0
*/
private boolean myWriteToLegacyLobColumns = false;
/** /**
* Constructor * Constructor
*/ */
@ -2431,8 +2423,8 @@ public class JpaStorageSettings extends StorageSettings {
* This setting controls the validation issue severity to report when a code validation * This setting controls the validation issue severity to report when a code validation
* finds that the code is present in the given CodeSystem, but the display name being * finds that the code is present in the given CodeSystem, but the display name being
* validated doesn't match the expected value(s). Defaults to * validated doesn't match the expected value(s). Defaults to
* {@link IValidationSupport.IssueSeverity#WARNING}. Set this * {@link ca.uhn.fhir.context.support.IValidationSupport.IssueSeverity#WARNING}. Set this
* value to {@link IValidationSupport.IssueSeverity#INFORMATION} * value to {@link ca.uhn.fhir.context.support.IValidationSupport.IssueSeverity#INFORMATION}
* if you don't want to see display name validation issues at all in resource validation * if you don't want to see display name validation issues at all in resource validation
* outcomes. * outcomes.
* *
@ -2447,8 +2439,8 @@ public class JpaStorageSettings extends StorageSettings {
* This setting controls the validation issue severity to report when a code validation * This setting controls the validation issue severity to report when a code validation
* finds that the code is present in the given CodeSystem, but the display name being * finds that the code is present in the given CodeSystem, but the display name being
* validated doesn't match the expected value(s). Defaults to * validated doesn't match the expected value(s). Defaults to
* {@link IValidationSupport.IssueSeverity#WARNING}. Set this * {@link ca.uhn.fhir.context.support.IValidationSupport.IssueSeverity#WARNING}. Set this
* value to {@link IValidationSupport.IssueSeverity#INFORMATION} * value to {@link ca.uhn.fhir.context.support.IValidationSupport.IssueSeverity#INFORMATION}
* if you don't want to see display name validation issues at all in resource validation * if you don't want to see display name validation issues at all in resource validation
* outcomes. * outcomes.
* *
@ -2462,33 +2454,6 @@ public class JpaStorageSettings extends StorageSettings {
myIssueSeverityForCodeDisplayMismatch = theIssueSeverityForCodeDisplayMismatch; myIssueSeverityForCodeDisplayMismatch = theIssueSeverityForCodeDisplayMismatch;
} }
/**
* This method returns whether data will be stored in LOB columns as well as the columns
* introduced to migrate away from LOB. Writing to LOB columns is set to false by
* default. Enabling the setting will effectively double the persisted information.
* If enabled, a careful monitoring of LOB table (if applicable) is required to avoid
* exceeding the table maximum capacity.
*
* @since 7.2.0
*/
public boolean isWriteToLegacyLobColumns() {
return myWriteToLegacyLobColumns;
}
/**
* This setting controls whether data will be stored in LOB columns as well as the columns
* introduced to migrate away from LOB. Writing to LOB columns is set to false by
* default. Enabling the setting will effectively double the persisted information.
* When enabled, a careful monitoring of LOB table (if applicable) is required to avoid
* exceeding the table maximum capacity.
*
* @param theWriteToLegacyLobColumns
* @since 7.2.0
*/
public void setWriteToLegacyLobColumns(boolean theWriteToLegacyLobColumns) {
myWriteToLegacyLobColumns = theWriteToLegacyLobColumns;
}
/** /**
* This setting controls whether MdmLink and other non-resource DB history is enabled. * This setting controls whether MdmLink and other non-resource DB history is enabled.
* <p/> * <p/>

View File

@ -333,6 +333,10 @@ public abstract class BaseRequestPartitionHelperSvc implements IRequestPartition
return !myNonPartitionableResourceNames.contains(theResourceType); return !myNonPartitionableResourceNames.contains(theResourceType);
} }
protected abstract RequestPartitionId validateAndNormalizePartitionIds(RequestPartitionId theRequestPartitionId);
protected abstract RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId theRequestPartitionId);
private void validateSinglePartitionForCreate( private void validateSinglePartitionForCreate(
RequestPartitionId theRequestPartitionId, @Nonnull String theResourceName, Pointcut thePointcut) { RequestPartitionId theRequestPartitionId, @Nonnull String theResourceName, Pointcut thePointcut) {
validateRequestPartitionNotNull(theRequestPartitionId, thePointcut); validateRequestPartitionNotNull(theRequestPartitionId, thePointcut);