Skip to content

Commit

Permalink
Add Dicom Calling Node to Dicom Export -> Dicom Send. #575
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Aug 23, 2024
1 parent d3148e5 commit 802c1bc
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ public AcquirePublishPanel() {
}

public void publishDirDicom(
File exportDirDicom, AbstractDicomNode destinationNode, List<AcquireImageInfo> toPublish) {
File exportDirDicom,
AbstractDicomNode destinationNode,
String callingAet,
List<AcquireImageInfo> toPublish) {
SwingWorker<DicomState, File> publishDicomTask = null;
if (destinationNode instanceof DefaultDicomNode defaultDicomNode) {
publishDicomTask = publishDicomDimse(exportDirDicom, defaultDicomNode.getDicomNode());
publishDicomTask =
publishDicomDimse(exportDirDicom, defaultDicomNode.getDicomNode(), callingAet);
} else if (destinationNode instanceof final DicomWebNode node) {
publishDicomTask = publishStow(exportDirDicom, node, toPublish);
}
Expand All @@ -94,7 +98,8 @@ public void publishDirDicom(
}
}

public PublishDicomTask publishDicomDimse(File exportDirDicom, DicomNode destNdde) {
public PublishDicomTask publishDicomDimse(
File exportDirDicom, DicomNode destNode, String callingAet) {
DicomProgress dicomProgress = new DicomProgress();
Supplier<DicomState> publish =
() -> {
Expand All @@ -105,14 +110,10 @@ public PublishDicomTask publishDicomDimse(File exportDirDicom, DicomNode destNdd
connectOptions.setConnectTimeout(3000);
connectOptions.setAcceptTimeout(5000);
params.setConnectOptions(connectOptions);
DicomNode callingNode =
new DicomNode(
GuiUtils.getUICore()
.getSystemPreferences()
.getProperty("weasis.aet", "WEASIS_AE")); // NON-NLS
DicomNode callingNode = new DicomNode(callingAet); // NON-NLS
try {
return CStore.process(
params, callingNode, destNdde, exportFilesDicomPath, dicomProgress);
params, callingNode, destNode, exportFilesDicomPath, dicomProgress);
} finally {
FileUtil.recursiveDelete(exportDirDicom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
package org.weasis.acquire.explorer.gui.dialog;

import static org.weasis.core.api.gui.Insertable.ITEM_SEPARATOR_LARGE;
import static org.weasis.core.api.gui.Insertable.ITEM_SEPARATOR_SMALL;

import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand Down Expand Up @@ -65,6 +68,8 @@ public class AcquirePublishDialog extends JDialog {
private static final String LAST_SEL_NODE = "lastSelectedNode";
public static final String P_LAST_RESOLUTION = "last.resolution";
public static final String PREFERENCE_NODE = "publish"; // NON-NLS
private static final String LAST_CALLING_NODE = "lastCallingNode";
private final JComboBox<AbstractDicomNode> comboCallingNode = new JComboBox<>();

public enum Resolution {
ORIGINAL(Messages.getString("AcquirePublishDialog.original"), Integer.MAX_VALUE),
Expand Down Expand Up @@ -174,10 +179,21 @@ private JPanel initContent() {
JLabel lblDestination =
new JLabel(
Messages.getString("AcquirePublishDialog.lblDestination.text") + StringUtil.COLON);
GuiUtils.setPreferredWidth(comboNode, 210, 185);
AbstractDicomNode.addTooltipToComboList(comboNode);
loadDicomNodes();
contentPane.add(lblDestination, "split 2, span"); // NON-NLS
contentPane.add(comboNode, " wrap"); // NON-NLS

JPanel panel = GuiUtils.getFlowLayoutPanel(ITEM_SEPARATOR_SMALL, 0, lblDestination, comboNode);
if (comboCallingNode.getItemCount() > 0) {
AbstractDicomNode.addTooltipToComboList(comboCallingNode);
JLabel lblCalling = new JLabel("Calling Node" + StringUtil.COLON);
GuiUtils.setPreferredWidth(comboCallingNode, 160, 120);

panel.add(GuiUtils.boxHorizontalStrut(ITEM_SEPARATOR_LARGE));
panel.add(lblCalling);
panel.add(comboCallingNode);
}
contentPane.add(panel, "split 5, span, wrap"); // NON-NLS

publishButton = new JButton(Messages.getString("AcquirePublishDialog.publish"));
publishButton.addActionListener(e -> publishAction());
Expand All @@ -201,14 +217,23 @@ private void loadDicomNodes() {
AbstractDicomNode.loadDicomNodes(comboNode, AbstractDicomNode.Type.DICOM, UsageType.STORAGE);
AbstractDicomNode.loadDicomNodes(comboNode, AbstractDicomNode.Type.WEB, UsageType.STORAGE);
String desc = MediaImporterFactory.EXPORT_PERSISTENCE.getProperty(LAST_SEL_NODE);
AbstractDicomNode.selectDicomNode(comboNode, desc);
AbstractDicomNode.selectDicomNode(comboNode.getModel(), desc);

if (comboNode.getItemCount() == 0) {
comboNode.addItem(getDestinationConfiguration());
}
} else {
comboNode.addItem(getDestinationConfiguration());
}

String weasisAet =
GuiUtils.getUICore().getSystemPreferences().getProperty("weasis.aet"); // NON-NLS
if (!StringUtil.hasText(weasisAet)) {
AbstractDicomNode.loadDicomNodes(
comboCallingNode, AbstractDicomNode.Type.DICOM_CALLING, UsageType.STORAGE);
String calling = MediaImporterFactory.EXPORT_PERSISTENCE.getProperty(LAST_CALLING_NODE);
AbstractDicomNode.selectDicomNode(comboCallingNode.getModel(), calling);
}
}

private static AbstractDicomNode getDestinationConfiguration() {
Expand Down Expand Up @@ -313,7 +338,17 @@ private SwingWorker<File, AcquireImageInfo> getFileAcquireImageInfoSwingWorker(

if (exportDirDicom != null) {
AbstractDicomNode node = (AbstractDicomNode) comboNode.getSelectedItem();
publishPanel.publishDirDicom(exportDirDicom, node, toPublish);
String weasisAet =
GuiUtils.getUICore()
.getSystemPreferences()
.getProperty("weasis.aet"); // NON-NLS
if (!StringUtil.hasText(weasisAet)) {
weasisAet =
comboCallingNode.getSelectedItem() == null
? "WEASIS_AE"
: ((DefaultDicomNode) comboCallingNode.getSelectedItem()).getAeTitle();
}
publishPanel.publishDirDicom(exportDirDicom, node, weasisAet, toPublish);
clearAndHide();
} else {
JOptionPane.showMessageDialog(
Expand Down Expand Up @@ -373,6 +408,11 @@ public void clearAndHide() {
if (node != null) {
MediaImporterFactory.EXPORT_PERSISTENCE.setProperty(LAST_SEL_NODE, node.getDescription());
}
final AbstractDicomNode callingNode = (AbstractDicomNode) comboCallingNode.getSelectedItem();
if (callingNode != null) {
MediaImporterFactory.EXPORT_PERSISTENCE.setProperty(
LAST_CALLING_NODE, callingNode.getDescription());
}
Preferences prefs =
BundlePreferences.getDefaultPreferences(AppProperties.getBundleContext(this.getClass()));
if (prefs != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ private DicomSorter() {}

private static boolean isEncapsulatedOrSR(MediaSeriesGroup series) {
String s1 = TagD.getTagValue(series, Tag.SOPClassUID, String.class);
return s1 != null && (s1.startsWith("1.2.840.10008.5.1.4.1.1.88") || s1.startsWith("1.2.840.10008.5.1.4.1.1.104"));
return s1 != null
&& (s1.startsWith("1.2.840.10008.5.1.4.1.1.88")
|| s1.startsWith("1.2.840.10008.5.1.4.1.1.104"));
}

public static SortingTime getStudyDateSorting() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.weasis.core.api.gui.util.AppProperties;
import org.weasis.core.api.gui.util.GuiUtils;
import org.weasis.core.api.service.BundlePreferences;
import org.weasis.core.api.service.WProperties;
import org.weasis.core.api.util.ResourceUtil;
import org.weasis.core.util.FileUtil;
import org.weasis.core.util.StringUtil;
Expand Down Expand Up @@ -457,9 +458,8 @@ public static void addTooltipToComboList(final JComboBox<? extends AbstractDicom
}
}

public static void selectDicomNode(JComboBox<AbstractDicomNode> comboNode, String desc) {
if (comboNode != null && StringUtil.hasText(desc)) {
ComboBoxModel<AbstractDicomNode> model = comboNode.getModel();
public static void selectDicomNode(ComboBoxModel<AbstractDicomNode> model, String desc) {
if (model != null && StringUtil.hasText(desc)) {
for (int i = 0; i < model.getSize(); i++) {
if (desc.equals(model.getElementAt(i).getDescription())) {
model.setSelectedItem(model.getElementAt(i));
Expand All @@ -468,4 +468,19 @@ public static void selectDicomNode(JComboBox<AbstractDicomNode> comboNode, Strin
}
}
}

public static void nodeSelectionPersistence(
WProperties prefs, AbstractDicomNode node, String key) {
if (node != null && prefs != null) {
prefs.setProperty(key, node.getDescription());
}
}

public static void restoreNodeSelection(
WProperties prefs, ComboBoxModel<AbstractDicomNode> model, String key) {
if (prefs != null) {
String desc = prefs.getProperty(key);
selectDicomNode(model, desc);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.dcm4che3.util.UIDUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.weasis.core.api.gui.util.GuiUtils;
import org.weasis.core.api.image.AffineTransformOp;
import org.weasis.core.api.image.LayoutConstraints;
import org.weasis.core.api.image.ZoomOp.Interpolation;
Expand All @@ -57,6 +56,7 @@
import org.weasis.core.ui.util.ImagePrint;
import org.weasis.core.ui.util.PrintOptions;
import org.weasis.core.util.MathUtil;
import org.weasis.dicom.explorer.pref.node.DefaultDicomNode;
import org.weasis.dicom.explorer.pref.node.DicomPrintNode;
import org.weasis.dicom.explorer.print.DicomPrintDialog.FilmSize;
import org.weasis.opencv.data.PlanarImage;
Expand Down Expand Up @@ -267,7 +267,7 @@ public static BufferedImage createGrayBufferedImage(int destWidth, int destHeigh
return new BufferedImage(cm, r, false, null);
}

public void printImage(BufferedImage image) throws Exception {
public void printImage(BufferedImage image, DefaultDicomNode selectedItem) throws Exception {
Attributes filmSessionAttrs = new Attributes();
Attributes filmBoxAttrs = new Attributes();
Attributes imageBoxAttrs = new Attributes();
Expand All @@ -283,11 +283,7 @@ public void printImage(BufferedImage image) throws Exception {

// writeDICOM(new File("/tmp/print.dcm"), dicomImage);

String weasisAet =
GuiUtils.getUICore()
.getSystemPreferences()
.getProperty("weasis.aet", "WEASIS_AE"); // NON-NLS

String weasisAet = selectedItem == null ? "WEASIS_AE" : selectedItem.getAeTitle(); // NON-NLS
Device device = new Device(weasisAet);
ApplicationEntity ae = new ApplicationEntity(weasisAet);
Connection conn = new Connection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.weasis.core.api.gui.util.GuiUtils;
import org.weasis.core.api.gui.util.WinUtil;
import org.weasis.core.api.media.data.ImageElement;
import org.weasis.core.api.service.WProperties;
import org.weasis.core.ui.editor.image.ImageViewerEventManager;
import org.weasis.core.ui.editor.image.ImageViewerPlugin;
import org.weasis.core.ui.editor.image.ViewCanvas;
Expand All @@ -36,6 +37,9 @@
import org.weasis.core.util.StringUtil;
import org.weasis.dicom.explorer.Messages;
import org.weasis.dicom.explorer.pref.node.AbstractDicomNode;
import org.weasis.dicom.explorer.pref.node.AbstractDicomNode.UsageType;
import org.weasis.dicom.explorer.pref.node.DefaultDicomNode;
import org.weasis.dicom.explorer.pref.node.DicomNodeDialog;
import org.weasis.dicom.explorer.pref.node.DicomPrintNode;

/**
Expand All @@ -45,6 +49,9 @@
public class DicomPrintDialog<I extends ImageElement> extends JDialog {
private static final Logger LOGGER = LoggerFactory.getLogger(DicomPrintDialog.class);

private static final String LAST_SEL_NODE = "lastSelNode";
private static final String LAST_CALLING_NODE = "lastCallingNode";

public enum FilmSize {
IN8X10("8INX10IN", 8, 10), // NON-NLS
IN8_5X11("8_5INX11IN", 8.5, 11), // NON-NLS
Expand Down Expand Up @@ -115,6 +122,7 @@ public static FilmSize getInstance(String val, FilmSize defaultValue) {

private DicomPrintOptionPane optionPane;
private JComboBox<AbstractDicomNode> printersComboBox;
private final JComboBox<AbstractDicomNode> comboCallingNode = new JComboBox<>();
private final ImageViewerEventManager<I> eventManager;

/** Creates new form DicomPrintDialog */
Expand Down Expand Up @@ -148,6 +156,8 @@ private void initComponents() {
AbstractDicomNode.loadDicomNodes(printersComboBox, AbstractDicomNode.Type.PRINTER);
GuiUtils.setPreferredWidth(printersComboBox, 200, 185);
AbstractDicomNode.addTooltipToComboList(printersComboBox);
AbstractDicomNode.restoreNodeSelection(
getPersistence(), printersComboBox.getModel(), LAST_SEL_NODE);

Component horizontalStrut = Box.createHorizontalStrut(20);
printersCfg.add(horizontalStrut);
Expand Down Expand Up @@ -183,13 +193,24 @@ private void initComponents() {
optionPane = new DicomPrintOptionPane();
panel.add(optionPane, "newline, gaptop 10, spanx"); // NON-NLS

JLabel lblCalling = new JLabel("Calling Node" + StringUtil.COLON);
AbstractDicomNode.loadDicomNodes(
comboCallingNode, AbstractDicomNode.Type.DICOM_CALLING, UsageType.STORAGE);
GuiUtils.setPreferredWidth(comboCallingNode, 185, 150);
AbstractDicomNode.addTooltipToComboList(comboCallingNode);
AbstractDicomNode.restoreNodeSelection(
getPersistence(), comboCallingNode.getModel(), LAST_CALLING_NODE);

panel.add(lblCalling, "newline, growx 0, alignx trailing"); // NON-NLS
panel.add(comboCallingNode, "growx, alignx trailing, gapright 25");

JButton printButton = new JButton(Messages.getString("DicomPrintDialog.print"));
printButton.addActionListener(this::printButtonActionPerformed);
getRootPane().setDefaultButton(printButton);
JButton cancelButton = new JButton(Messages.getString("DicomPrintDialog.cancel"));
cancelButton.addActionListener(evt -> doClose());

panel.add(printButton, "newline, skip, growx 0, alignx trailing"); // NON-NLS
panel.add(printButton, "skip, growx 0, alignx trailing"); // NON-NLS
panel.add(cancelButton, "gap 15lp 0lp 10lp 10lp"); // NON-NLS
setContentPane(panel);
}
Expand Down Expand Up @@ -228,7 +249,8 @@ private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {
}

try {
dicomPrint.printImage(dicomPrint.printImage(layout));
dicomPrint.printImage(
dicomPrint.printImage(layout), (DefaultDicomNode) comboCallingNode.getSelectedItem());
} catch (Exception e) {
LOGGER.error("DICOM Print Service", e);
JOptionPane.showMessageDialog(
Expand All @@ -242,6 +264,12 @@ private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {
}

private void doClose() {
AbstractDicomNode.nodeSelectionPersistence(
getPersistence(), (AbstractDicomNode) printersComboBox.getSelectedItem(), LAST_SEL_NODE);
AbstractDicomNode.nodeSelectionPersistence(
getPersistence(),
(AbstractDicomNode) comboCallingNode.getSelectedItem(),
LAST_CALLING_NODE);
dispose();
}

Expand All @@ -251,4 +279,8 @@ private void applyOptionsFromSelected() {
optionPane.applyOptions(printNode.getPrintOptions());
}
}

public static WProperties getPersistence() {
return GuiUtils.getUICore().getPluginPersistence(DicomNodeDialog.class.getPackageName());
}
}
Loading

0 comments on commit 802c1bc

Please sign in to comment.