Search in sources :

Example 1 with ForwardDestination

use of org.karnak.backend.dicom.ForwardDestination 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 2 with ForwardDestination

use of org.karnak.backend.dicom.ForwardDestination 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)

Example 3 with ForwardDestination

use of org.karnak.backend.dicom.ForwardDestination in project karnak by OsiriX-Foundation.

the class EchoServiceTest method should_retrieve_status_destinations.

@Test
void should_retrieve_status_destinations() throws IOException {
    // Init data
    ForwardDicomNode forwardDicomNode = new ForwardDicomNode("fwdAeTitle");
    Optional<ForwardDicomNode> forwardDicomNodeOpt = Optional.of(forwardDicomNode);
    DicomNode dicomNode = new DicomNode("fwdAeTitle", 1111);
    ForwardDestination forwardDestination = new DicomForwardDestination(forwardDicomNode, dicomNode);
    WebForwardDestination webForwardDestination = new WebForwardDestination(forwardDicomNode, "http://test.com");
    List<ForwardDestination> forwardDestinations = Arrays.asList(forwardDestination, webForwardDestination);
    DicomState dicomState = new DicomState();
    dicomState.setStatus(444);
    // Mock
    Mockito.when(gatewaySetUpServiceMock.getDestinationNode(Mockito.anyString())).thenReturn(forwardDicomNodeOpt);
    Mockito.when(gatewaySetUpServiceMock.getDestinations(Mockito.any(ForwardDicomNode.class))).thenReturn(forwardDestinations);
    MockedStatic<Echo> echoMock = Mockito.mockStatic(Echo.class);
    echoMock.when(() -> Echo.process(Mockito.any(AdvancedParams.class), Mockito.any(ForwardDicomNode.class), Mockito.any(DicomNode.class))).thenReturn(dicomState);
    // Call service
    List<DestinationEcho> destinationEchos = echoService.retrieveStatusConfiguredDestinations("fwdAeTitle");
    // Test results
    Mockito.verify(gatewaySetUpServiceMock, Mockito.times(1)).getDestinationNode(Mockito.anyString());
    assertEquals(2, destinationEchos.size());
    assertEquals("fwdAeTitle", destinationEchos.get(0).getAet());
    assertEquals(444, destinationEchos.get(0).getStatus());
    assertEquals("http://test.com/studies", destinationEchos.get(1).getUrl());
    assertEquals(0, destinationEchos.get(1).getStatus());
}
Also used : DestinationEcho(org.karnak.backend.model.echo.DestinationEcho) Echo(org.weasis.dicom.op.Echo) AdvancedParams(org.weasis.dicom.param.AdvancedParams) DestinationEcho(org.karnak.backend.model.echo.DestinationEcho) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DicomState(org.weasis.dicom.param.DicomState) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) Test(org.junit.jupiter.api.Test)

Example 4 with ForwardDestination

use of org.karnak.backend.dicom.ForwardDestination in project karnak by OsiriX-Foundation.

the class EchoServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) {
    res.setContentType("text/xml");
    PrintWriter out = null;
    try {
        out = res.getWriter();
    } catch (IOException e) {
        String errorMsg = "Cannot write response";
        LOGGER.error(errorMsg);
        ServletUtil.sendResponseError(res, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg);
        return;
    }
    String aet = req.getParameter("srcAET");
    if (globalConfig == null) {
        String errorMsg = "Missing 'GlobalConfig' from current ServletContext";
        LOGGER.error(errorMsg);
        ServletUtil.sendResponseError(res, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg);
        return;
    }
    // Echo service, only work for the out stream configuration
    AdvancedParams params = new AdvancedParams();
    ConnectOptions connectOptions = new ConnectOptions();
    connectOptions.setConnectTimeout(3000);
    connectOptions.setAcceptTimeout(5000);
    params.setConnectOptions(connectOptions);
    StringBuilder sb = new StringBuilder("<destinations>");
    Optional<ForwardDicomNode> srcNode = globalConfig.getDestinationNode(aet);
    if (srcNode.isPresent()) {
        List<ForwardDestination> list = globalConfig.getDestinations(srcNode.get());
        for (ForwardDestination val : list) {
            if (val instanceof DicomForwardDestination) {
                DicomNode calledNode = ((DicomForwardDestination) val).getStreamSCU().getCalledNode();
                // TODO isUseAetDest
                DicomState dicomState = Echo.process(params, srcNode.get(), calledNode);
                sb.append("<destination ");
                sb.append("aet=");
                sb.append(calledNode.getAet());
                sb.append(">");
                sb.append(dicomState.getStatus());
                sb.append("</destination>\n");
            } else if (val instanceof WebForwardDestination) {
                WebForwardDestination d = (WebForwardDestination) val;
                sb.append("<destination ");
                sb.append("url=");
                sb.append(d.getRequestURL());
                sb.append(">");
                // To implement
                // sb.append(d.getStowRS().);
                sb.append("</destination>\n");
            }
        }
    }
    sb.append("</destinations>\n");
    out.println(sb);
}
Also used : IOException(java.io.IOException) AdvancedParams(org.weasis.dicom.param.AdvancedParams) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DicomState(org.weasis.dicom.param.DicomState) ConnectOptions(org.weasis.dicom.param.ConnectOptions) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) DicomForwardDestination(org.karnak.backend.dicom.DicomForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) WebForwardDestination(org.karnak.backend.dicom.WebForwardDestination) PrintWriter(java.io.PrintWriter)

Aggregations

ForwardDestination (org.karnak.backend.dicom.ForwardDestination)4 ForwardDicomNode (org.karnak.backend.dicom.ForwardDicomNode)4 DicomForwardDestination (org.karnak.backend.dicom.DicomForwardDestination)3 WebForwardDestination (org.karnak.backend.dicom.WebForwardDestination)3 DicomNode (org.weasis.dicom.param.DicomNode)3 IOException (java.io.IOException)2 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)2 AdvancedParams (org.weasis.dicom.param.AdvancedParams)2 DicomState (org.weasis.dicom.param.DicomState)2 PrintWriter (java.io.PrintWriter)1 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1