Search in sources :

Example 1 with ForwardDicomNode

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);
    }
}
Also used : HashMap(java.util.HashMap) ConditionEditor(org.karnak.backend.model.editor.ConditionEditor) ArrayList(java.util.ArrayList) Attributes(org.dcm4che3.data.Attributes) FilterEditor(org.karnak.backend.model.editor.FilterEditor) IOException(java.io.IOException) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Document(org.jsoup.nodes.Document) StreamRegistryEditor(org.karnak.backend.model.editor.StreamRegistryEditor) DicomProgress(org.weasis.dicom.param.DicomProgress) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) DeIdentifyEditor(org.karnak.backend.model.editor.DeIdentifyEditor) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) AttributeEditor(org.weasis.dicom.param.AttributeEditor) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode)

Example 2 with ForwardDicomNode

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);
    }
}
Also used : ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) ScheduledFuture(java.util.concurrent.ScheduledFuture) VR(org.dcm4che3.data.VR) Attributes(org.dcm4che3.data.Attributes) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DicomNode(org.weasis.dicom.param.DicomNode) Service(org.springframework.stereotype.Service) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) DestinationRepo(org.karnak.backend.data.repo.DestinationRepo) PDVInputStream(org.dcm4che3.net.PDVInputStream) Logger(org.slf4j.Logger) Params(org.karnak.backend.dicom.Params) Set(java.util.Set) IOException(java.io.IOException) Status(org.dcm4che3.net.Status) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Association(org.dcm4che3.net.Association) List(java.util.List) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) Tag(org.dcm4che3.data.Tag) BasicCStoreSCP(org.dcm4che3.net.service.BasicCStoreSCP) Optional(java.util.Optional) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) PresentationContext(org.dcm4che3.net.pdu.PresentationContext) Params(org.karnak.backend.dicom.Params) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) IOException(java.io.IOException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 3 with ForwardDicomNode

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));
        }
    });
}
Also used : DicomState(org.weasis.dicom.param.DicomState) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DestinationEcho(org.karnak.backend.model.echo.DestinationEcho) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination)

Example 4 with ForwardDicomNode

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();
    }
}
Also used : ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) AttributeEditor(org.weasis.dicom.param.AttributeEditor) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) Attributes(org.dcm4che3.data.Attributes) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) VersionEntity(org.karnak.backend.data.entity.VersionEntity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtil(org.weasis.core.util.StringUtil) ConnectOptions(org.weasis.dicom.param.ConnectOptions) ForwardNodeRepo(org.karnak.backend.data.repo.ForwardNodeRepo) Scheduled(org.springframework.scheduling.annotation.Scheduled) DicomNode(org.weasis.dicom.param.DicomNode) ArrayList(java.util.ArrayList) TlsOptions(org.weasis.dicom.param.TlsOptions) VersionRepo(org.karnak.backend.data.repo.VersionRepo) SystemPropertyUtil(org.karnak.backend.util.SystemPropertyUtil) Service(org.springframework.stereotype.Service) Map(java.util.Map) DestinationRepo(org.karnak.backend.data.repo.DestinationRepo) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) NodeEventType(org.karnak.backend.enums.NodeEventType) StreamRegistryEditor(org.karnak.backend.model.editor.StreamRegistryEditor) Path(java.nio.file.Path) DicomSourceNodeEntity(org.karnak.backend.data.entity.DicomSourceNodeEntity) FilterEditor(org.karnak.backend.model.editor.FilterEditor) ForwardNodeEntity(org.karnak.backend.data.entity.ForwardNodeEntity) LangUtil(org.weasis.core.util.LangUtil) NodeEvent(org.karnak.backend.model.event.NodeEvent) Logger(org.slf4j.Logger) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Set(java.util.Set) IOException(java.io.IOException) ConditionEditor(org.karnak.backend.model.editor.ConditionEditor) DicomProgress(org.weasis.dicom.param.DicomProgress) List(java.util.List) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) Document(org.jsoup.nodes.Document) AdvancedParams(org.weasis.dicom.param.AdvancedParams) Optional(java.util.Optional) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) DestinationType(org.karnak.backend.enums.DestinationType) DeIdentifyEditor(org.karnak.backend.model.editor.DeIdentifyEditor) Jsoup(org.jsoup.Jsoup) Collections(java.util.Collections) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) NodeEventType(org.karnak.backend.enums.NodeEventType) DicomSourceNodeEntity(org.karnak.backend.data.entity.DicomSourceNodeEntity) ForwardNodeEntity(org.karnak.backend.data.entity.ForwardNodeEntity) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode)

Example 5 with ForwardDicomNode

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);
    }
}
Also used : ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) ArrayList(java.util.ArrayList) ForwardNodeEntity(org.karnak.backend.data.entity.ForwardNodeEntity) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination)

Aggregations

ForwardDicomNode (org.karnak.backend.dicom.ForwardDicomNode)7 DicomForwardDestination (org.karnak.backend.dicom.DicomForwardDestination)6 WebForwardDestination (org.karnak.backend.dicom.WebForwardDestination)6 DicomNode (org.weasis.dicom.param.DicomNode)6 ForwardDestination (org.karnak.backend.dicom.ForwardDestination)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 Attributes (org.dcm4che3.data.Attributes)3 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)3 AdvancedParams (org.weasis.dicom.param.AdvancedParams)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Document (org.jsoup.nodes.Document)2 ForwardNodeEntity (org.karnak.backend.data.entity.ForwardNodeEntity)2 KheopsAlbumsEntity (org.karnak.backend.data.entity.KheopsAlbumsEntity)2 DestinationRepo (org.karnak.backend.data.repo.DestinationRepo)2 DestinationEcho (org.karnak.backend.model.echo.DestinationEcho)2