Search in sources :

Example 1 with DicomNode

use of org.weasis.dicom.param.DicomNode 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 DicomNode

use of org.weasis.dicom.param.DicomNode in project karnak by OsiriX-Foundation.

the class Util method getEchoResponse.

public static boolean getEchoResponse(StringBuilder result, String callingAET, DicomNode calledNode, boolean fontIcon, String format, Integer connectTimeout) {
    boolean success = false;
    boolean xml = "XML".equalsIgnoreCase(format);
    try {
        AdvancedParams params = new AdvancedParams();
        DicomState state;
        if (connectTimeout != null) {
            ConnectOptions connectOptions = new ConnectOptions();
            connectOptions.setConnectTimeout(connectTimeout);
            params.setConnectOptions(connectOptions);
            state = Echo.process(params, new DicomNode(callingAET), calledNode);
        } else {
            state = Echo.process(callingAET, calledNode);
        }
        success = state.getStatus() == Status.Success;
        if (xml) {
            result.append("<DcmStatus>");
            if (success) {
                result.append("Success").append("</DcmStatus>");
                result.append("<DcmStatusMessage>").append(state.getMessage()).append("</DcmStatusMessage>");
            } else {
                result.append("Error ").append(Integer.toHexString(state.getStatus())).append("</DcmStatus>");
                result.append("<DcmStatusMessage>").append(state.getMessage()).append("</DcmStatusMessage>");
            }
        } else {
            // "HTML" and anything else
            result.append(success ? "<span style=\"color:green\">" + getOKItem(fontIcon) : "<span style=\"color:red\">" + getWarningItem(fontIcon));
            result.append("</span> DICOM Status: ");
            if (success) {
                result.append("Success");
            } else {
                result.append("error code ");
                result.append(Integer.toHexString(state.getStatus()));
            }
            result.append("<br>DICOM Message: ");
            result.append(state.getMessage());
            result.append("<br>");
        }
    } catch (Throwable e) {
        if (xml) {
            result.append("<DcmStatus>DICOM unexpected error</DcmStatus>");
            result.append("<DcmStatusMessage>").append(e.getMessage()).append("</DcmStatusMessage>");
        } else {
            // "HTML" and anything else
            result.append("<span style=\"color:red\">");
            result.append(getWarningItem(fontIcon));
            result.append(" DICOM unexpected error: ");
            result.append(e.getMessage());
            result.append("</span><br>");
        }
    }
    return success;
}
Also used : DicomState(org.weasis.dicom.param.DicomState) ConnectOptions(org.weasis.dicom.param.ConnectOptions) AdvancedParams(org.weasis.dicom.param.AdvancedParams) DicomNode(org.weasis.dicom.param.DicomNode)

Example 3 with DicomNode

use of org.weasis.dicom.param.DicomNode in project karnak by OsiriX-Foundation.

the class DicomEchoLogic method dicomEcho.

public void dicomEcho(DicomEchoQueryData data) {
    String aet = data.getCalledAet();
    String hostname = data.getCalledHostname();
    int port = data.getCalledPort();
    StringBuilder result = new StringBuilder();
    result.append("<P><h6>Network status</h6>");
    boolean reachable = Util.getNetworkResponse(result, aet, hostname, port, true);
    result.append("</P>");
    if (reachable) {
        result.append("<br><P>");
        DicomNode dcmNode = new DicomNode(data.getCalledAet(), data.getCalledHostname(), data.getCalledPort());
        result.append("<h6>DICOM Echo: ");
        result.append(dcmNode.getAet());
        result.append("</h6>");
        Util.getEchoResponse(result, data.getCallingAet(), dcmNode, true, "HTML");
        result.append("</P>");
    }
    view.displayStatus(result.toString());
}
Also used : DicomNode(org.weasis.dicom.param.DicomNode)

Example 4 with DicomNode

use of org.weasis.dicom.param.DicomNode in project karnak by OsiriX-Foundation.

the class DicomEchoThread method call.

@Override
public String call() throws Exception {
    StringBuilder result = new StringBuilder();
    result.append("<P>");
    DicomNode dcmNode = node.getCalledNode();
    result.append("<h6>DICOM Echo: ");
    result.append(node.toString());
    result.append("</h6>");
    result.append(dcmNode.toString());
    result.append("<br>");
    result.append("<small>");
    boolean success = Util.getEchoResponse(result, "PACSMONITOR", dcmNode, true, "HTML", 3000);
    if (!success) {
        Util.getNetworkResponse(result, dcmNode.getAet(), dcmNode.getHostname(), dcmNode.getPort(), true);
    }
    result.append("</small>");
    result.append("</P>");
    result.append("<hr>");
    return result.toString();
}
Also used : DicomNode(org.weasis.dicom.param.DicomNode)

Example 5 with DicomNode

use of org.weasis.dicom.param.DicomNode in project karnak by OsiriX-Foundation.

the class ForwardDestinationTest method when_uid_rlelossless_or_endian_should_return_explicit_vr_little_endian.

@Test
void when_uid_rlelossless_or_endian_should_return_explicit_vr_little_endian() throws IOException {
    // Init data
    ForwardDicomNode forwardDicomNode = new ForwardDicomNode("fwdAeTitle");
    DicomNode dicomNode = new DicomNode("fwdAeTitle", 1111);
    ForwardDestination forwardDestination = new DicomForwardDestination(forwardDicomNode, dicomNode);
    // Mock
    dicomUtilsMock.when(() -> DicomUtils.isNative(Mockito.anyString())).thenReturn(true);
    dicomOutputDataMock.when(() -> DicomOutputData.isSupportedSyntax(Mockito.anyString())).thenReturn(false);
    // Call method
    String outputTransferSyntax = forwardDestination.getOutputTransferSyntax(UID.RLELossless);
    // Test result
    assertEquals(UID.ExplicitVRLittleEndian, outputTransferSyntax);
    // Call method
    outputTransferSyntax = forwardDestination.getOutputTransferSyntax(UID.ImplicitVRLittleEndian);
    // Test result
    assertEquals(UID.ExplicitVRLittleEndian, outputTransferSyntax);
    // Call method
    outputTransferSyntax = forwardDestination.getOutputTransferSyntax(UID.ExplicitVRBigEndian);
    // Test result
    assertEquals(UID.ExplicitVRLittleEndian, outputTransferSyntax);
}
Also used : DicomNode(org.weasis.dicom.param.DicomNode) Test(org.junit.jupiter.api.Test)

Aggregations

DicomNode (org.weasis.dicom.param.DicomNode)23 Test (org.junit.jupiter.api.Test)12 Attributes (org.dcm4che3.data.Attributes)7 ForwardDicomNode (org.karnak.backend.dicom.ForwardDicomNode)6 AttributeEditorContext (org.weasis.dicom.param.AttributeEditorContext)6 IOException (java.io.IOException)5 DicomForwardDestination (org.karnak.backend.dicom.DicomForwardDestination)5 WebForwardDestination (org.karnak.backend.dicom.WebForwardDestination)5 DicomState (org.weasis.dicom.param.DicomState)5 ArrayList (java.util.ArrayList)4 ForwardDestination (org.karnak.backend.dicom.ForwardDestination)4 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)3 AdvancedParams (org.weasis.dicom.param.AdvancedParams)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2