Skip to content

Commit

Permalink
QIDO RS: support filter Studies by Storage System fix #1742
Browse files Browse the repository at this point in the history
  • Loading branch information
gunterze committed Dec 31, 2018
1 parent b5fb5e7 commit 75a18e5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1419,70 +1419,14 @@ public Stream<String> getStorageIDsOfCluster(String clusterID) {
.map(StorageDescriptor::getStorageID);
}

private List<String> getOtherStorageIDs(StorageDescriptor desc) {
public List<String> getOtherStorageIDs(StorageDescriptor desc) {
return desc.getStorageClusterID() != null
? getStorageIDsOfCluster(desc.getStorageClusterID())
.filter(storageID -> !storageID.equals(desc.getStorageID()))
.collect(Collectors.toList())
: Collections.emptyList();
}

public List<String> getStudyStorageIDs(StorageDescriptor desc) {
return desc.getExportStorageID() != null
? addPowerSet(false, getOtherStorageIDs(desc), desc.getStorageID(), desc.getExportStorageID())
: addPowerSet(false, getOtherStorageIDs(desc), desc.getStorageID());
}

public List<String> getStudyStorageIDs(
String storageID, String storageClustered, String storageExported) {
StorageDescriptor desc = getStorageDescriptorNotNull(storageID);
if ("false".equals(storageClustered)) {
return desc.getExportStorageID() == null || "false".equals(storageExported)
? Collections.singletonList(desc.getStorageID())
: storageExported == null
? Arrays.asList(desc.getStorageID(), concat(desc.getStorageID(), desc.getExportStorageID()))
: Collections.singletonList(concat(desc.getStorageID(), desc.getExportStorageID()));
}

List<String> studyStorageIDs = addPowerSet(storageClustered != null, getOtherStorageIDs(desc), desc.getStorageID());
List<String> exportedStudyStorageIDs = new ArrayList<>();

if (desc.getExportStorageID() != null)
exportedStudyStorageIDs = addPowerSet(storageClustered != null, getOtherStorageIDs(desc), desc.getStorageID(),
desc.getExportStorageID());

if (storageExported == null && desc.getExportStorageID() != null)
studyStorageIDs.addAll(exportedStudyStorageIDs);

return desc.getExportStorageID() != null && "true".equals(storageExported)
? exportedStudyStorageIDs : studyStorageIDs;
}

private static String concat(String... common) {
return StringUtils.concat(common, '\\');
}

private static List<String> addPowerSet(boolean excludeEmptySet, List<String> storageIDs, String... common) {
if (storageIDs.isEmpty()) {
if (excludeEmptySet)
return Collections.emptyList();

Arrays.sort(common);
return Collections.singletonList(StringUtils.concat(common, '\\'));
}
return IntStream.range(excludeEmptySet ? 1 : 0, 1 << storageIDs.size()).mapToObj(i -> {
String[] a = Arrays.copyOf(common, common.length + Integer.bitCount(i));
int j = common.length;
int mask = 1;
for (String storageID : storageIDs) {
if ((i & mask) != 0) a[j++] = storageID;
mask <<= 1;
}
Arrays.sort(a);
return StringUtils.concat(a, '\\');
}).collect(Collectors.toList());
}

public QueueDescriptor getQueueDescriptor(String queueName) {
return queueDescriptorMap.get(queueName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* @author Gunter Zeilinger <gunterze@gmail.com>
Expand Down Expand Up @@ -228,4 +230,56 @@ public void setStorageClusterID(String storageClusterID) {
this.storageClusterID = storageClusterID;
}

public List<String> getStudyStorageIDs(List<String> otherStorageIDs) {
return exportStorageID != null
? addPowerSet(false, otherStorageIDs, exportStorageID, storageID)
: addPowerSet(false, otherStorageIDs, storageID);
}

public List<String> getStudyStorageIDs(List<String> otherStorageIDs,
Boolean storageClustered, Boolean storageExported) {
if (storageClustered != null && storageClustered && storageClusterID == null
|| storageExported != null && storageExported && exportStorageID == null)
return Collections.emptyList();

if (storageClusterID == null || storageClustered != null && !storageClustered) {
return exportStorageID == null || storageExported != null && !storageExported
? Collections.singletonList(storageID)
: storageExported == null
? addPowerSet(false, Collections.singletonList(exportStorageID), storageID)
: addPowerSet(false, Collections.emptyList(), exportStorageID, storageID);
}

if (exportStorageID == null || storageExported != null && !storageExported) {
return addPowerSet(storageClustered != null, otherStorageIDs, storageID);
}

List<String> studyStorageIDs = addPowerSet(
storageClustered != null, otherStorageIDs, exportStorageID, storageID);
if (storageExported == null) {
studyStorageIDs.addAll(addPowerSet(storageClustered != null, otherStorageIDs, storageID));
}
return studyStorageIDs;
}

private static List<String> addPowerSet(boolean excludeEmptySet, List<String> storageIDs, String... common) {
if (storageIDs.isEmpty()) {
if (excludeEmptySet)
return Collections.emptyList();

Arrays.sort(common);
return Collections.singletonList(StringUtils.concat(common, '\\'));
}
return IntStream.range(excludeEmptySet ? 1 : 0, 1 << storageIDs.size()).mapToObj(i -> {
String[] a = Arrays.copyOf(common, common.length + Integer.bitCount(i));
int j = common.length;
int mask = 1;
for (String storageID : storageIDs) {
if ((i & mask) != 0) a[j++] = storageID;
mask <<= 1;
}
Arrays.sort(a);
return StringUtils.concat(a, '\\');
}).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,9 @@ private List<String> getStorageIDsOfCluster(StorageDescriptor desc) {
}

private List<String> getStudyStorageIDs(StorageDescriptor desc) {
return device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class)
.getStudyStorageIDs(desc);
return desc.getStudyStorageIDs(
device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class)
.getOtherStorageIDs(desc));
}

}
19 changes: 12 additions & 7 deletions dcm4chee-arc-qido/src/main/java/org/dcm4chee/arc/qido/QidoRS.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
import org.dcm4che3.net.service.QueryRetrieveLevel2;
import org.dcm4che3.util.StringUtils;
import org.dcm4che3.ws.rs.MediaTypes;
import org.dcm4chee.arc.conf.ArchiveAEExtension;
import org.dcm4chee.arc.conf.ArchiveDeviceExtension;
import org.dcm4chee.arc.conf.AttributeSet;
import org.dcm4chee.arc.conf.Entity;
import org.dcm4chee.arc.conf.*;
import org.dcm4chee.arc.entity.*;
import org.dcm4chee.arc.query.Query;
import org.dcm4chee.arc.query.QueryContext;
Expand Down Expand Up @@ -499,9 +496,13 @@ private QueryContext newQueryContext(String method, QueryAttributes queryAttrs,
queryParam.setExternalRetrieveAET(externalRetrieveAET);
queryParam.setExternalRetrieveAETNot(externalRetrieveAETNot);
queryParam.setExpirationDate(expirationDate);
if (storageID != null)
queryParam.setStorageIDs(device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class)
.getStudyStorageIDs(storageID, storageClustered, storageExported));
if (storageID != null) {
ArchiveDeviceExtension arcdev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
StorageDescriptor storageDesc = arcdev.getStorageDescriptorNotNull(storageID);
List<String> otherStorageIDs = arcdev.getOtherStorageIDs(storageDesc);
queryParam.setStorageIDs(storageDesc.getStudyStorageIDs(otherStorageIDs,
parseBoolean(storageClustered), parseBoolean(storageExported)));
}
if (patientVerificationStatus != null)
queryParam.setPatientVerificationStatus(Patient.VerificationStatus.valueOf(patientVerificationStatus));
QueryContext ctx = service.newQueryContextQIDO(request, method, ae, queryParam);
Expand All @@ -520,6 +521,10 @@ private QueryContext newQueryContext(String method, QueryAttributes queryAttrs,
return ctx;
}

private static Boolean parseBoolean(String s) {
return s != null ? Boolean.valueOf(s) : null;
}

private static int parseInt(String s) {
return s != null ? Integer.parseInt(s) : 0;
}
Expand Down

0 comments on commit 75a18e5

Please sign in to comment.