use of org.karnak.backend.dicom.ForwardDicomNode in project karnak by OsiriX-Foundation.
the class GatewaySetUpService method addDestinationNode.
private void addDestinationNode(List<ForwardDestination> dstList, ForwardDicomNode fwdSrcNode, DestinationEntity dstNode) {
try {
List<AttributeEditor> editors = new ArrayList<>();
if (!dstNode.getCondition().isEmpty()) {
editors.add(new ConditionEditor(dstNode.getCondition()));
}
final boolean filterBySOPClassesEnable = dstNode.isFilterBySOPClasses();
if (filterBySOPClassesEnable) {
editors.add(new FilterEditor(dstNode.getSOPClassUIDEntityFilters()));
}
final List<KheopsAlbumsEntity> kheopsAlbumEntities = dstNode.getKheopsAlbumEntities();
SwitchingAlbum switchingAlbum = new SwitchingAlbum();
if (kheopsAlbumEntities != null && !kheopsAlbumEntities.isEmpty()) {
editors.add((Attributes dcm, AttributeEditorContext context) -> {
kheopsAlbumEntities.forEach(kheopsAlbums -> {
switchingAlbum.apply(dstNode, kheopsAlbums, dcm);
});
});
}
StreamRegistryEditor streamRegistryEditor = new StreamRegistryEditor();
editors.add(streamRegistryEditor);
boolean deidentificationEnable = dstNode.isDesidentification();
boolean profileDefined = dstNode.getProjectEntity() != null && dstNode.getProjectEntity().getProfileEntity() != null;
if (deidentificationEnable && profileDefined) {
// TODO add an option in destination model
editors.add(new DeIdentifyEditor(dstNode));
}
DicomProgress progress = new DicomProgress();
if (dstNode.isActivate()) {
if (dstNode.getDestinationType() == DestinationType.stow) {
// parse headers to hashmap
HashMap<String, String> map = new HashMap<>();
String headers = dstNode.getHeaders();
Document doc = Jsoup.parse(headers);
String key = doc.getElementsByTag("key").text();
String value = doc.getElementsByTag("value").text();
if (StringUtil.hasText(key)) {
map.put(key, value);
}
WebForwardDestination fwd = new WebForwardDestination(dstNode.getId(), fwdSrcNode, dstNode.getUrl(), map, progress, editors, dstNode.getTransferSyntax(), dstNode.isTranscodeOnlyUncompressed());
if (kheopsAlbumEntities != null && !kheopsAlbumEntities.isEmpty()) {
progress.addProgressListener((DicomProgress dicomProgress) -> {
Attributes dcm = dicomProgress.getAttributes();
kheopsAlbumEntities.forEach(kheopsAlbums -> {
switchingAlbum.applyAfterTransfer(kheopsAlbums, dcm);
});
});
}
dstList.add(fwd);
} else {
DicomNode destinationNode = new DicomNode(dstNode.getAeTitle(), dstNode.getHostname(), dstNode.getPort());
DicomForwardDestination dest = new DicomForwardDestination(dstNode.getId(), getDefaultAdvancedParameters(), fwdSrcNode, destinationNode, dstNode.getUseaetdest(), progress, editors, dstNode.getTransferSyntax(), dstNode.isTranscodeOnlyUncompressed());
dstList.add(dest);
}
}
} catch (IOException e) {
LOGGER.error("Cannot build ForwardDestination", e);
}
}
use of org.karnak.backend.dicom.ForwardDicomNode in project karnak by OsiriX-Foundation.
the class CStoreSCPService method store.
@Override
protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp) throws IOException {
Optional<ForwardDicomNode> sourceNode = destinations.keySet().stream().filter(n -> n.getForwardAETitle().equals(as.getCalledAET())).findFirst();
if (sourceNode.isEmpty()) {
throw new IllegalStateException("Cannot find the forward AeTitle " + as.getCalledAET());
}
ForwardDicomNode fwdNode = sourceNode.get();
List<ForwardDestination> destList = destinations.get(fwdNode);
if (destList == null || destList.isEmpty()) {
throw new IllegalStateException("No DICOM destinations for " + fwdNode);
}
DicomNode callingNode = DicomNode.buildRemoteDicomNode(as);
Set<DicomNode> srcNodes = fwdNode.getAcceptedSourceNodes();
boolean valid = srcNodes.isEmpty() || srcNodes.stream().anyMatch(n -> n.getAet().equals(callingNode.getAet()) && (!n.isValidateHostname() || n.equalsHostname(callingNode.getHostname())));
if (!valid) {
rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized);
LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", callingNode, rq.getString(Tag.AffectedSOPInstanceUID));
return;
}
rsp.setInt(Tag.Status, VR.US, status);
try {
Params p = new Params(rq.getString(Tag.AffectedSOPInstanceUID), rq.getString(Tag.AffectedSOPClassUID), pc.getTransferSyntax(), priority, data, as);
// Update transfer status of destinations
updateTransferStatus(destList);
forwardService.storeMultipleDestination(fwdNode, destList, p);
} catch (Exception e) {
throw new DicomServiceException(Status.ProcessingFailure, e);
}
}
use of org.karnak.backend.dicom.ForwardDicomNode in project karnak by OsiriX-Foundation.
the class EchoService method fillDestinationsStatus.
/**
* Fill the list of destinations status
*
* @param destinationEchos List to fill
* @param sourceNode Source Node
* @param destinations Destinations found
*/
private void fillDestinationsStatus(List<DestinationEcho> destinationEchos, ForwardDicomNode sourceNode, List<ForwardDestination> destinations) {
destinations.forEach(destination -> {
// Case DICOM
if (destination instanceof DicomForwardDestination) {
DicomNode calledNode = ((DicomForwardDestination) destination).getStreamSCU().getCalledNode();
// Retrieve the status of the dicom node
DicomState dicomState = Echo.process(buildEchoProcessParams(3000, 5000), sourceNode, calledNode);
// Add the destination and its status
destinationEchos.add(new DestinationEcho(calledNode.getAet(), null, dicomState.getStatus()));
} else // Case Stow
if (destination instanceof WebForwardDestination) {
WebForwardDestination d = (WebForwardDestination) destination;
// Add the destination and its status
destinationEchos.add(new DestinationEcho(null, d.getRequestURL(), 0));
}
});
}
use of org.karnak.backend.dicom.ForwardDicomNode in project karnak by OsiriX-Foundation.
the class GatewaySetUpService method update.
public void update(NodeEvent event) {
NodeEventType type = event.getEventType();
Object src = event.getSource();
Long id = event.getForwardNode().getId();
String aet = event.getForwardNode().getFwdAeTitle();
Optional<ForwardDicomNode> val = destMap.keySet().stream().filter(f -> id.equals(f.getId())).findFirst();
ForwardDicomNode fwdNode;
if (val.isEmpty()) {
fwdNode = new ForwardDicomNode(aet, null, id);
destMap.put(fwdNode, new ArrayList<>(2));
} else {
fwdNode = val.get();
}
if (src instanceof DicomSourceNodeEntity) {
DicomSourceNodeEntity srcNode = (DicomSourceNodeEntity) src;
if (type == NodeEventType.ADD) {
fwdNode.addAcceptedSourceNode(srcNode.getId(), srcNode.getAeTitle(), srcNode.getHostname());
} else if (type == NodeEventType.REMOVE) {
fwdNode.getAcceptedSourceNodes().removeIf(s -> srcNode.getId().equals(s.getId()));
} else if (type == NodeEventType.UPDATE) {
fwdNode.getAcceptedSourceNodes().removeIf(s -> srcNode.getId().equals(s.getId()));
fwdNode.addAcceptedSourceNode(srcNode.getId(), srcNode.getAeTitle(), srcNode.getHostname());
}
} else if (src instanceof DestinationEntity) {
DestinationEntity dstNode = (DestinationEntity) src;
if (type == NodeEventType.ADD) {
addDestinationNode(destMap.get(fwdNode), fwdNode, dstNode);
} else if (type == NodeEventType.REMOVE) {
destMap.get(fwdNode).removeIf(d -> dstNode.getId().equals(d.getId()));
} else if (type == NodeEventType.UPDATE) {
destMap.get(fwdNode).removeIf(d -> dstNode.getId().equals(d.getId()));
addDestinationNode(destMap.get(fwdNode), fwdNode, dstNode);
}
} else if (src instanceof ForwardNodeEntity) {
ForwardNodeEntity fw = (ForwardNodeEntity) src;
if (type == NodeEventType.ADD) {
addAcceptedSourceNodes(fwdNode, fw);
destMap.put(fwdNode, addDestinationNodes(fwdNode, fw));
} else if (type == NodeEventType.REMOVE) {
destMap.remove(fwdNode);
} else if (type == NodeEventType.UPDATE) {
if (!aet.equals(fwdNode.getAet())) {
ForwardDicomNode newfwdNode = new ForwardDicomNode(aet, null, id);
for (DicomNode srcNode : fwdNode.getAcceptedSourceNodes()) {
newfwdNode.getAcceptedSourceNodes().add(srcNode);
}
destMap.put(newfwdNode, destMap.remove(fwdNode));
}
}
} else {
reloadGatewayPersistence();
}
}
use of org.karnak.backend.dicom.ForwardDicomNode in project karnak by OsiriX-Foundation.
the class GatewaySetUpService method reloadGatewayPersistence.
public void reloadGatewayPersistence() {
List<ForwardNodeEntity> list = new ArrayList<>(forwardNodeRepo.findAll());
for (ForwardNodeEntity forwardNodeEntity : list) {
ForwardDicomNode fwdSrcNode = new ForwardDicomNode(forwardNodeEntity.getFwdAeTitle(), null, forwardNodeEntity.getId());
addAcceptedSourceNodes(fwdSrcNode, forwardNodeEntity);
List<ForwardDestination> dstList = new ArrayList<>(forwardNodeEntity.getDestinationEntities().size());
for (DestinationEntity dstNode : forwardNodeEntity.getDestinationEntities()) {
addDestinationNode(dstList, fwdSrcNode, dstNode);
}
destMap.put(fwdSrcNode, dstList);
}
}
Aggregations