diff --git a/pom.xml b/pom.xml index 73241cae..70e15300 100644 --- a/pom.xml +++ b/pom.xml @@ -352,6 +352,12 @@ + + com.vnetpublishing.java + super-user-application + 0.0.5 + + \ No newline at end of file diff --git a/src/org/petctviewer/orthanc/anonymize/CloseWindowAdapter.java b/src/org/petctviewer/orthanc/anonymize/CloseWindowAdapter.java index 0bfa9fba..302cad79 100644 --- a/src/org/petctviewer/orthanc/anonymize/CloseWindowAdapter.java +++ b/src/org/petctviewer/orthanc/anonymize/CloseWindowAdapter.java @@ -63,7 +63,6 @@ public void windowClosing(WindowEvent e) { private void closeAll() { if (monitoring.isRunningMonitoringService()) monitoring.closeAllMonitoringServices(); if(runOrthanc.getIsStarted()) { - runOrthanc.stopOrthanc(); } frame.dispose(); diff --git a/src/org/petctviewer/orthanc/anonymize/QueryFillStore.java b/src/org/petctviewer/orthanc/anonymize/QueryFillStore.java index 1edc05e0..324a7782 100644 --- a/src/org/petctviewer/orthanc/anonymize/QueryFillStore.java +++ b/src/org/petctviewer/orthanc/anonymize/QueryFillStore.java @@ -18,7 +18,6 @@ package org.petctviewer.orthanc.anonymize; import java.io.IOException; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,7 @@ public QueryFillStore(ParametreConnexionHttp connexion){ } public QueryFillStore(ParametreConnexionHttp connexion, String level, String inputType, String input, - String date, String studyDesc) throws MalformedURLException{ + String date, String studyDesc) { this.connexion=connexion; @@ -126,7 +125,7 @@ public String getQuery(){ return this.query; } - private String sendQuery(String action) throws IOException{ + private String sendQuery(String action){ StringBuilder sb = new StringBuilder(); if(action.equals("storeIDs") && this.url.toString().contains("tools/find")){ @@ -140,7 +139,7 @@ private String sendQuery(String action) throws IOException{ return sb.toString(); } - private void storeIDs() throws IOException{ + private void storeIDs(){ if(this.level.equals("series")){ @@ -188,9 +187,10 @@ public ArrayList getIDs(){ } // Renvoie les responses JSON par niveau de query - public List getJsonResponse() throws IOException{ + public List getJsonResponse() { ids.removeAll(ids); this.storeIDs(); + List jsonResponses=new ArrayList(); for(String id : ids){ @@ -237,7 +237,7 @@ public Object[] getAET() { for (int i=0 ; iThe description has been changed."); frame.pack(); } @@ -142,7 +135,7 @@ public Serie getSerie(int rowIndex){ return this.series.get(rowIndex); } - public boolean checkSopClassUid(String instanceUid) throws IOException{ + public boolean checkSopClassUid(String instanceUid) { if(instanceUid != null){ url="/instances/" + instanceUid + "/metadata/SopClassUid"; StringBuilder sb =connexionHttp.makeGetConnectionAndStringBuilder(url); @@ -194,7 +187,7 @@ public ArrayList getSeries(){ return this.series; } - public void addSerie(String studyID) throws IOException, ParseException{ + public void addSerie(String studyID) { this.studyID = studyID; QueryFillStore querySeries = new QueryFillStore(connexionHttp,"series", null, studyID, null, null); diff --git a/src/org/petctviewer/orthanc/anonymize/TableDataSeries.java b/src/org/petctviewer/orthanc/anonymize/TableDataSeries.java index 0e568c4a..3f4ee9ed 100644 --- a/src/org/petctviewer/orthanc/anonymize/TableDataSeries.java +++ b/src/org/petctviewer/orthanc/anonymize/TableDataSeries.java @@ -18,14 +18,9 @@ package org.petctviewer.orthanc.anonymize; import java.io.IOException; -//import java.net.HttpURLConnection; -import java.text.ParseException; import java.util.ArrayList; import java.util.List; -import javax.swing.JFrame; -import javax.swing.JLabel; -//import javax.swing.SwingWorker; import javax.swing.table.AbstractTableModel; import org.json.simple.JSONArray; @@ -42,12 +37,10 @@ public class TableDataSeries extends AbstractTableModel{ private String url; private ParametreConnexionHttp connexionHttp; - public TableDataSeries(ParametreConnexionHttp connexionHttp, JLabel state, JFrame frame){ + public TableDataSeries(ParametreConnexionHttp connexionHttp){ super(); //Recupere les settings this.connexionHttp=connexionHttp; - //this.state = state; - //this.frame = frame; } @@ -145,7 +138,7 @@ public void removeSerie(int rowIndex){ fireTableRowsDeleted(rowIndex, rowIndex); } - public void addSerie(String studyID) throws IOException, ParseException{ + public void addSerie(String studyID) { //this.studyID = studyID; QueryFillStore querySeries = new QueryFillStore(connexionHttp,"series", null, studyID, null, null); List jsonResponsesPatient=querySeries.getJsonResponse(); diff --git a/src/org/petctviewer/orthanc/anonymize/TablePatientsMouseListener.java b/src/org/petctviewer/orthanc/anonymize/TablePatientsMouseListener.java index e5e07963..1520190e 100644 --- a/src/org/petctviewer/orthanc/anonymize/TablePatientsMouseListener.java +++ b/src/org/petctviewer/orthanc/anonymize/TablePatientsMouseListener.java @@ -48,7 +48,7 @@ public void mouseClicked(MouseEvent event) { this.modeleSeries.clear(); try { - if(this.modele.getRowCount() != 0){ + if(this.modele.getRowCount() != 0 && tableau.getSelectedRow() != -1){ String patientName = (String)this.tableau.getValueAt(this.tableau.getSelectedRow(), 0); String patientID = (String)this.tableau.getValueAt(this.tableau.getSelectedRow(), 1); String patientUID = (String)this.tableau.getValueAt(this.tableau.getSelectedRow(), 2); diff --git a/src/org/petctviewer/orthanc/anonymize/TableStudiesMouseListener.java b/src/org/petctviewer/orthanc/anonymize/TableStudiesMouseListener.java index 277cc2e6..20a18cee 100644 --- a/src/org/petctviewer/orthanc/anonymize/TableStudiesMouseListener.java +++ b/src/org/petctviewer/orthanc/anonymize/TableStudiesMouseListener.java @@ -19,8 +19,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.IOException; - import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.ListSelectionModel; @@ -50,9 +48,6 @@ public void mouseClicked(MouseEvent event) { String studyID = (String)this.tableau.getValueAt(this.tableau.getSelectedRow(), 3); this.modeleSeries.addSerie(studyID); } - } catch (IOException e1) { - e1.printStackTrace(); - } catch (Exception e1) { //ignore } diff --git a/src/org/petctviewer/orthanc/anonymize/VueAnon.java b/src/org/petctviewer/orthanc/anonymize/VueAnon.java index 5ad59adc..54930504 100644 --- a/src/org/petctviewer/orthanc/anonymize/VueAnon.java +++ b/src/org/petctviewer/orthanc/anonymize/VueAnon.java @@ -48,7 +48,6 @@ import java.util.List; import java.util.prefs.Preferences; -import javax.swing.AbstractAction; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; @@ -89,8 +88,6 @@ import com.michaelbaranov.microba.calendar.DatePicker; -import ij.IJ; -import ij.WindowManager; import ij.plugin.PlugIn; import org.petctviewer.orthanc.*; @@ -105,7 +102,7 @@ import org.petctviewer.orthanc.setup.Run_Orthanc; -public class VueAnon extends JFrame implements PlugIn{ +public class VueAnon extends JFrame implements PlugIn, ActionListener{ private static final long serialVersionUID = 1L; protected JTabbedPane tabbedPane; @@ -172,7 +169,7 @@ public class VueAnon extends JFrame implements PlugIn{ private JPopupMenu popMenuSeries = new JPopupMenu(); private ArrayList zipContent = new ArrayList(); private ArrayList manageContent = new ArrayList(); - private JPanel anonTablesPanel; + protected JPanel anonTablesPanel; private int anonCount; @@ -282,7 +279,7 @@ public void buildGui(){ //On set les objets necessaires modelePatients = new TableDataPatientsAnon(connexionHttp); modeleExportSeries = new TableDataExportSeries(connexionHttp, this, stateExports); - modeleSeries = new TableDataSeries(connexionHttp, state, this); + modeleSeries = new TableDataSeries(connexionHttp); modeleExportStudies = new TableDataExportStudies(connexionHttp); modeleAnonStudies = new TableDataAnonStudies(connexionHttp); modeleStudies = new TableDataStudies(connexionHttp); @@ -706,9 +703,7 @@ public void actionPerformed(ActionEvent e) { modeleSeries.addSerie(tableauStudies.getValueAt(tableauStudies.convertRowIndexToModel(tableauStudies.getSelectedRow()), 3).toString()); } catch (IOException e1) { e1.printStackTrace(); - } catch (ParseException e1) { - e1.printStackTrace(); - } + } } }); JMenuItem menuItemDeleteAllSop = new JMenuItem("Remove all secondary captures"); @@ -722,9 +717,7 @@ public void actionPerformed(ActionEvent e) { modeleSeries.addSerie(tableauStudies.getValueAt(tableauStudies.convertRowIndexToModel(tableauStudies.getSelectedRow()), 3).toString()); } catch (IOException e1) { e1.printStackTrace(); - } catch (ParseException e1) { - e1.printStackTrace(); - } + } } }); JMenuItem menuItemDeleteSeries = new JMenuItem("Delete this serie"); @@ -1227,7 +1220,7 @@ public void actionPerformed(ActionEvent e) { anonBtn = new JButton("Anonymize"); anonBtn.setPreferredSize(new Dimension(120,27)); - anonBtn.addActionListener(new AnonAction()); + anonBtn.addActionListener(this); //Label to show the currently selected profile in the main panel JLabel profileLabel = new JLabel(); @@ -2704,262 +2697,244 @@ private void removeFromToolList(ArrayList zipContent, JComboBox } } } - - - // Anonymization query - private class AnonAction extends AbstractAction{ - private static final long serialVersionUID = 1L; - int dialogResult = JOptionPane.YES_OPTION; - @Override - public void actionPerformed(ActionEvent arg0) { - dialogResult = JOptionPane.YES_OPTION; - anonCount = 0; - SwingWorker workerRemoveScAndSr = new SwingWorker(){ - @Override - protected Void doInBackground() { - try { - modeleAnonStudies.removeScAndSr(); - } catch(FileNotFoundException e){ - // Ignore - } catch (IOException e) { - e.printStackTrace(); + public void actionPerformed(ActionEvent arg0) { + anonCount = 0; + + SwingWorker worker = new SwingWorker(){ + int dialogResult=JOptionPane.YES_OPTION; + @Override + protected Void doInBackground() { + //////////// Filling the user preferences //////////// + if(anonProfiles.getSelectedItem().equals("Custom")){ + for(int i = 0; i < 2; i++){ + if(bodyCharList[i].isSelected()){ + if(jprefer.getInt("bodyCharac", 0) != i){ + jprefer.putInt("bodyCharac", i); + } + } } - return null; - } - }; - SwingWorker worker = new SwingWorker(){ - - @Override - protected Void doInBackground() { - //////////// Filling the user preferences //////////// - if(anonProfiles.getSelectedItem().equals("Custom")){ - for(int i = 0; i < 2; i++){ - if(bodyCharList[i].isSelected()){ - if(jprefer.getInt("bodyCharac", 0) != i){ - jprefer.putInt("bodyCharac", i); - } - } - } - for(int i = 0; i < 2; i++){ - if(datesList[i].isSelected()){ - if(jprefer.getInt("Dates", 0) != i){ - jprefer.putInt("Dates", i); - } + for(int i = 0; i < 2; i++){ + if(datesList[i].isSelected()){ + if(jprefer.getInt("Dates", 0) != i){ + jprefer.putInt("Dates", i); } } - for(int i = 0; i < 2; i++){ - if(bdList[i].isSelected()){ - if(jprefer.getInt("BD", 0) != i){ - jprefer.putInt("BD", i); - } + } + for(int i = 0; i < 2; i++){ + if(bdList[i].isSelected()){ + if(jprefer.getInt("BD", 0) != i){ + jprefer.putInt("BD", i); } } - for(int i = 0; i < 2; i++){ - if(ptList[i].isSelected()){ - if(jprefer.getInt("PT", 0) != i){ - jprefer.putInt("PT", i); - } + } + for(int i = 0; i < 2; i++){ + if(ptList[i].isSelected()){ + if(jprefer.getInt("PT", 0) != i){ + jprefer.putInt("PT", i); } } - for(int i = 0; i < 2; i++){ - if(scList[i].isSelected()){ - if(jprefer.getInt("SC", 0) != i){ - jprefer.putInt("SC", i); - } + } + for(int i = 0; i < 2; i++){ + if(scList[i].isSelected()){ + if(jprefer.getInt("SC", 0) != i){ + jprefer.putInt("SC", i); } } - for(int i = 0; i < 2; i++){ - if(descList[i].isSelected()){ - if(jprefer.getInt("DESC", 0) != i){ - jprefer.putInt("DESC", i); - } + } + for(int i = 0; i < 2; i++){ + if(descList[i].isSelected()){ + if(jprefer.getInt("DESC", 0) != i){ + jprefer.putInt("DESC", i); } } } + } - jprefer.put("profileAnon", anonProfiles.getSelectedItem().toString()); - - //Disable the anons button during anonymization - enableAnonButton(false); + jprefer.put("profileAnon", anonProfiles.getSelectedItem().toString()); - anonBtn.setText("Anonymizing"); - // SETTING UP THE CHOICES - for(int i = 0; i < 2; i++){ - if(i == 0){ - if(bodyCharList[i].isSelected()) - bodyCharChoice = Choice.KEEP; - if(datesList[i].isSelected()) - datesChoice = Choice.KEEP; - if(bdList[i].isSelected()) - bdChoice = Choice.KEEP; - if(ptList[i].isSelected()) - ptChoice = Choice.KEEP; - if(scList[i].isSelected()) - scChoice = Choice.KEEP; - if(descList[i].isSelected()) - descChoice = Choice.KEEP; - }else{ - if(bodyCharList[i].isSelected()) - bodyCharChoice = Choice.CLEAR; - if(datesList[i].isSelected()) - datesChoice = Choice.CLEAR; - if(bdList[i].isSelected()) - bdChoice = Choice.REPLACE; - if(ptList[i].isSelected()) - ptChoice = Choice.CLEAR; - if(scList[i].isSelected()) - scChoice = Choice.CLEAR; - if(descList[i].isSelected()) - descChoice = Choice.CLEAR; - } + //Disable the anons button during anonymization + enableAnonButton(false); + + anonBtn.setText("Anonymizing"); + // SETTING UP THE CHOICES + for(int i = 0; i < 2; i++){ + if(i == 0){ + if(bodyCharList[i].isSelected()) + bodyCharChoice = Choice.KEEP; + if(datesList[i].isSelected()) + datesChoice = Choice.KEEP; + if(bdList[i].isSelected()) + bdChoice = Choice.KEEP; + if(ptList[i].isSelected()) + ptChoice = Choice.KEEP; + if(scList[i].isSelected()) + scChoice = Choice.KEEP; + if(descList[i].isSelected()) + descChoice = Choice.KEEP; + }else{ + if(bodyCharList[i].isSelected()) + bodyCharChoice = Choice.CLEAR; + if(datesList[i].isSelected()) + datesChoice = Choice.CLEAR; + if(bdList[i].isSelected()) + bdChoice = Choice.REPLACE; + if(ptList[i].isSelected()) + ptChoice = Choice.CLEAR; + if(scList[i].isSelected()) + scChoice = Choice.CLEAR; + if(descList[i].isSelected()) + descChoice = Choice.CLEAR; } + } - int i = 0; - int j = 0; - try { - if(anonProfiles.getSelectedItem().equals("Full clearing")){ - if(modeleAnonStudies.getModalities().contains("NM") || - modeleAnonStudies.getModalities().contains("PT")){ - dialogResult = JOptionPane.showConfirmDialog (gui, - "Full clearing is not recommended for NM or PT modalities." - + "Are you sure you want to anonymize ?", - "Warning anonymizing PT/NM", - JOptionPane.WARNING_MESSAGE, - JOptionPane.YES_NO_OPTION); - } - } - if(modeleAnonStudies.getModalities().contains("US")){ - JOptionPane.showMessageDialog (gui, - "DICOM files with the US modality may have hard printed informations, " - + "you may want to check your files.", - "Warning anonymizing US", - JOptionPane.WARNING_MESSAGE); - } - - // Checking if several anonymized patients have the same ID or not - boolean similarIDs = false; - ArrayList newIDs = new ArrayList(); - for(int n = 0; n < anonPatientTable.getRowCount(); n++){ - String newID = modeleAnonPatients.getPatient(anonPatientTable.convertRowIndexToModel(n)).getNewID(); - if(newID != "" && !newIDs.contains(newID)){ - newIDs.add(newID); - }else if(newIDs.contains(newID)){ - similarIDs = true; - } - } - if(similarIDs){ + int i = 0; + int j = 0; + try { + + if(anonProfiles.getSelectedItem().equals("Full clearing")){ + if(modeleAnonStudies.getModalities().contains("NM") || + modeleAnonStudies.getModalities().contains("PT")){ dialogResult = JOptionPane.showConfirmDialog (gui, - "You have defined 2 or more identical IDs for anonymized patients, which is not recommended." - + " Are you sure you want to anonymize ?", - "Warning similar IDs", + "Full clearing is not recommended for NM or PT modalities." + + "Are you sure you want to anonymize ?", + "Warning anonymizing PT/NM", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); } - - if(dialogResult == JOptionPane.YES_OPTION){ + } + if(modeleAnonStudies.getModalities().contains("US")){ + JOptionPane.showMessageDialog (gui, + "DICOM files with the US modality may have hard printed informations, " + + "you may want to check your files.", + "Warning anonymizing US", + JOptionPane.WARNING_MESSAGE); + } + + // Checking if several anonymized patients have the same ID or not + boolean similarIDs = false; + ArrayList newIDs = new ArrayList(); + for(int n = 0; n < anonPatientTable.getRowCount(); n++){ + String newID = modeleAnonPatients.getPatient(anonPatientTable.convertRowIndexToModel(n)).getNewID(); + if(newID != "" && !newIDs.contains(newID)){ + newIDs.add(newID); + }else if(newIDs.contains(newID)){ + similarIDs = true; + } + } + if(similarIDs){ + dialogResult = JOptionPane.showConfirmDialog (gui, + "You have defined 2 or more identical IDs for anonymized patients, which is not recommended." + + " Are you sure you want to anonymize ?", + "Warning similar IDs", + JOptionPane.WARNING_MESSAGE, + JOptionPane.YES_NO_OPTION); + } + + if(dialogResult == JOptionPane.YES_OPTION){ - String substituteName = "A-" + jprefer.get("centerCode", "12345"); + String substituteName = "A-" + jprefer.get("centerCode", "12345"); - SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm"); - String substituteID = "A-" + df.format(new Date()); + SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm"); + String substituteID = "A-" + df.format(new Date()); - for(String patientID : modeleAnonStudies.getPatientIDs()){ - String newName = modeleAnonPatients.getPatient(anonPatientTable.convertRowIndexToModel(j)).getNewName(); - String newID = modeleAnonPatients.getPatient(anonPatientTable.convertRowIndexToModel(j)).getNewID(); - String newStudyID = ""; - if((newName == null || newName.equals("")) || (newID == null || newID.equals(""))){ - anonCount++; - } - if(newName == null || newName.equals("")){ - newName = substituteName + "^" + anonCount; - modeleAnonPatients.setValueAt(newName, anonPatientTable.convertRowIndexToModel(j), 3); - } + for(String patientID : modeleAnonStudies.getPatientIDs()){ + String newName = modeleAnonPatients.getPatient(anonPatientTable.convertRowIndexToModel(j)).getNewName(); + String newID = modeleAnonPatients.getPatient(anonPatientTable.convertRowIndexToModel(j)).getNewID(); + String newStudyID = ""; + if((newName == null || newName.equals("")) || (newID == null || newID.equals(""))){ + anonCount++; + } + if(newName == null || newName.equals("")){ + newName = substituteName + "^" + anonCount; + modeleAnonPatients.setValueAt(newName, anonPatientTable.convertRowIndexToModel(j), 3); + } - if(newID == null || newID.equals("")){ - newID = substituteID + "^" + anonCount; - modeleAnonPatients.setValueAt(newID, anonPatientTable.convertRowIndexToModel(j), 4); - } + if(newID == null || newID.equals("")){ + newID = substituteID + "^" + anonCount; + modeleAnonPatients.setValueAt(newID, anonPatientTable.convertRowIndexToModel(j), 4); + } - for(String uid : modeleAnonStudies.getOldOrthancUIDsWithID(patientID)){ - String newDesc = modeleAnonStudies.getNewDesc(uid); - QueryAnon quAnon; - quAnon = new QueryAnon(connexionHttp, bodyCharChoice, datesChoice, bdChoice, ptChoice, scChoice, descChoice, newName, newID, newDesc); - quAnon.setQuery(); - state.setText("Anonymization state - " + (i+1) + "/" + modeleAnonStudies.getStudies().size() + - "
(Do not use the toolbox while the current operation is not done)
"); - quAnon.sendQuery("studies", uid); - modeleAnonStudies.addNewUid(quAnon.getNewUID()); - i++; - newStudyID = quAnon.getNewUID(); - //Add anonymized study in export list - modeleExportStudies.addStudy(newName, newID, newStudyID); - } - - j++; + for(String uid : modeleAnonStudies.getOldOrthancUIDsWithID(patientID)){ + String newDesc = modeleAnonStudies.getNewDesc(uid); + QueryAnon quAnon; + quAnon = new QueryAnon(connexionHttp, bodyCharChoice, datesChoice, bdChoice, ptChoice, scChoice, descChoice, newName, newID, newDesc); + quAnon.setQuery(); + state.setText("Anonymization state - " + (i+1) + "/" + modeleAnonStudies.getStudies().size() + + "
(Do not use the toolbox while the current operation is not done)
"); + quAnon.sendQuery("studies", uid); + modeleAnonStudies.addNewUid(quAnon.getNewUID()); + i++; + newStudyID = quAnon.getNewUID(); + //Add anonymized study in export list + modeleExportStudies.addStudy(newName, newID, newStudyID); } - //Empty list - modeleAnonStudies.empty(); - modeleAnonPatients.clear(); - - - } - } catch (IOException e1) { - e1.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } - return null; - } - @Override - protected void done(){ - if(scList[1].isSelected()){ - workerRemoveScAndSr.execute(); - } - //Re-enable anon button - enableAnonButton(true); - anonBtn.setText("Anonymize"); - if(dialogResult == JOptionPane.YES_OPTION){ - state.setText("The data has successfully been anonymized."); - openCloseAnonTool(false); - pack(); - tabbedPane.setSelectedIndex(1); - modeleAnonPatients.clear(); - modeleAnonStudies.empty(); + j++; + } - } - if(tableauExportStudies.getRowCount() > 0){ - tableauExportStudies.setRowSelectionInterval(tableauExportStudies.getRowCount() - 1, tableauExportStudies.getRowCount() - 1); - } - modeleExportSeries.clear(); - try { - if(modeleExportStudies.getRowCount() > 0){ - String studyID = (String)tableauExportStudies.getValueAt(tableauExportStudies.getSelectedRow(), 5); - modeleExportSeries.addSerie(studyID); - tableauExportSeries.setRowSelectionInterval(0,0); + if(scList[1].isSelected()){ + modeleAnonStudies.removeScAndSr(); } - } catch (Exception e1) { - // IGNORE - } - //Si foncion a �t� fait avec le CTP on fait l'envoi auto A l'issue de l'anon - if(autoSendCTP) { - exportCTP.doClick(); - autoSendCTP=false; - } - if(anonymizeListener!=null) { - anonymizeListener.AnonymizationDone(); + + //Empty list + modeleAnonStudies.empty(); + modeleAnonPatients.clear(); + + } + } catch (IOException e1) { + e1.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); } - }; - if(!modeleAnonStudies.getOldOrthancUIDs().isEmpty()){ + return null; + } + + @Override + protected void done(){ + + //Re-enable anon button + enableAnonButton(true); + anonBtn.setText("Anonymize"); if(dialogResult == JOptionPane.YES_OPTION){ - worker.execute(); + state.setText("The data has successfully been anonymized."); + openCloseAnonTool(false); + pack(); + tabbedPane.setSelectedIndex(1); + modeleAnonPatients.clear(); + modeleAnonStudies.empty(); + + } + if(tableauExportStudies.getRowCount() > 0){ + tableauExportStudies.setRowSelectionInterval(tableauExportStudies.getRowCount() - 1, tableauExportStudies.getRowCount() - 1); + } + modeleExportSeries.clear(); + try { + if(modeleExportStudies.getRowCount() > 0){ + String studyID = (String)tableauExportStudies.getValueAt(tableauExportStudies.getSelectedRow(), 5); + modeleExportSeries.addSerie(studyID); + tableauExportSeries.setRowSelectionInterval(0,0); + } + } catch (Exception e1) { + // IGNORE + } + //Si foncion a �t� fait avec le CTP on fait l'envoi auto A l'issue de l'anon + if(autoSendCTP) { + exportCTP.doClick(); + autoSendCTP=false; + } + if(anonymizeListener!=null) { + anonymizeListener.AnonymizationDone(); } } + }; + if(!modeleAnonStudies.getOldOrthancUIDs().isEmpty()){ + worker.execute(); } } + public void enableAnonButton(boolean enable) { anonBtn.setEnabled(enable); addToAnon.setEnabled(enable); @@ -2974,8 +2949,6 @@ public void setAnonymizeListener(AnonymizeListener anonymizeListener) { // LAUNCHERS public static void main(String... args){ - System.setProperty("org.apache.commons.logging.Log", - "org.apache.commons.logging.impl.NoOpLog"); VueAnon anon=new VueAnon(); anon.setLocationRelativeTo(null); anon.setVisible(true); @@ -2986,13 +2959,13 @@ public static void main(String... args){ @Override public void run(String string) { VueAnon anon=new VueAnon(); - WindowManager.addWindow(gui); - IJ.register(VueAnon.class); anon.setLocationRelativeTo(null); anon.setVisible(true); } + + diff --git a/src/org/petctviewer/orthanc/ctpimport/CTP_Import_GUI.java b/src/org/petctviewer/orthanc/ctpimport/CTP_Import_GUI.java index 2033ec2b..70e87a72 100644 --- a/src/org/petctviewer/orthanc/ctpimport/CTP_Import_GUI.java +++ b/src/org/petctviewer/orthanc/ctpimport/CTP_Import_GUI.java @@ -11,6 +11,8 @@ import java.util.HashMap; import java.util.Set; +import javax.swing.JButton; + import org.petctviewer.orthanc.anonymize.VueAnon; import org.petctviewer.orthanc.importdicom.ImportDCM; @@ -45,7 +47,7 @@ public CTP_Import_GUI() { listePeers.setVisible(false); listeAETExport.setVisible(false); - addressFieldCTP.setText("http://kanoun.fr/"); + addressFieldCTP.setText("http://localhost/"); importCTP.addActionListener(new ActionListener() { @@ -64,6 +66,20 @@ public void actionPerformed(ActionEvent arg0) { openCloseAnonTool(true); tabbedPane.remove(2); listePeersCTP.setSelectedIndex(1); + + JButton selectSeries=new JButton("Select Series"); + this.anonTablesPanel.add(selectSeries); + selectSeries.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + Select_Series selectSeriesDialog=new Select_Series(connexionHttp, anonStudiesTable.getValueAt(anonStudiesTable.getSelectedRow(), 3).toString() ); + selectSeriesDialog.setVisible(true); + + + } + + }); this.revalidate(); this.pack(); this.setLocationRelativeTo(null); diff --git a/src/org/petctviewer/orthanc/ctpimport/Select_Series.java b/src/org/petctviewer/orthanc/ctpimport/Select_Series.java new file mode 100644 index 00000000..2e5dc104 --- /dev/null +++ b/src/org/petctviewer/orthanc/ctpimport/Select_Series.java @@ -0,0 +1,76 @@ +package org.petctviewer.orthanc.ctpimport; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.border.EmptyBorder; + +import org.petctviewer.orthanc.ParametreConnexionHttp; +import org.petctviewer.orthanc.anonymize.TableDataSeries; + +public class Select_Series extends JDialog { + + /** + * + */ + private static final long serialVersionUID = 1L; + private final JPanel contentPanel = new JPanel(); + protected JTable tableSeries; + + /** + * Launch the application. + */ + public static void main(String[] args) { + try { + Select_Series dialog = new Select_Series(new ParametreConnexionHttp(), null); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Create the dialog. + */ + public Select_Series(ParametreConnexionHttp connexionHttp, String studyUID) { + TableDataSeries tableSeriesModel=new TableDataSeries(connexionHttp); + tableSeriesModel.addSerie(studyUID); + tableSeries = new JTable(tableSeriesModel); + setBounds(100, 100, 450, 300); + getContentPane().setLayout(new BorderLayout()); + contentPanel.setLayout(new FlowLayout()); + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(contentPanel, BorderLayout.CENTER); + { + JScrollPane scrollPane = new JScrollPane(); + contentPanel.add(scrollPane); + { + + scrollPane.setViewportView(tableSeries); + } + } + { + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton okButton = new JButton("OK"); + okButton.setActionCommand("OK"); + buttonPane.add(okButton); + getRootPane().setDefaultButton(okButton); + } + { + JButton cancelButton = new JButton("Cancel"); + cancelButton.setActionCommand("Cancel"); + buttonPane.add(cancelButton); + } + } + } + +} diff --git a/src/org/petctviewer/orthanc/monitoring/Burner_Settings.java b/src/org/petctviewer/orthanc/monitoring/Burner_Settings.java index ee38e92d..05e2f98c 100644 --- a/src/org/petctviewer/orthanc/monitoring/Burner_Settings.java +++ b/src/org/petctviewer/orthanc/monitoring/Burner_Settings.java @@ -31,8 +31,6 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.prefs.Preferences; import java.awt.event.ActionEvent; import javax.swing.JRadioButton; diff --git a/src/org/petctviewer/orthanc/monitoring/CD_Burner.java b/src/org/petctviewer/orthanc/monitoring/CD_Burner.java index 4ee9ae8d..729ca250 100644 --- a/src/org/petctviewer/orthanc/monitoring/CD_Burner.java +++ b/src/org/petctviewer/orthanc/monitoring/CD_Burner.java @@ -30,6 +30,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -38,6 +39,7 @@ import java.util.zip.ZipInputStream; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -45,7 +47,8 @@ import org.petctviewer.orthanc.anonymize.ConvertZipAction; import javax.swing.JOptionPane; -import javax.swing.JTextArea; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; public class CD_Burner { @@ -56,16 +59,18 @@ public class CD_Burner { private String fijiDirectory; private Boolean deleteStudies; private String suportType; - private JTextArea textArea; + private JTable table_burning_history; private Path folder; private DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); private Date datenow; private ParametreConnexionHttp connexion; private Timer timer; + private JSONParser parser=new JSONParser(); + private HashMap burningStatus=new HashMap(); - public CD_Burner (ParametreConnexionHttp connexion, JTextArea textArea) { + public CD_Burner (ParametreConnexionHttp connexion, JTable table_burning_history) { this.connexion=connexion; - this.textArea=textArea; + this.table_burning_history=table_burning_history; setCDPreference(); } @@ -79,7 +84,6 @@ public void startCDMonitoring() { JOptionPane.showMessageDialog(null, "Go to settings Menu to set missing paths", "Set directories and date format", JOptionPane.ERROR_MESSAGE); } else { - textArea.append("Monitoring Orthanc \n"); Orthanc_Monitoring monitoring=new Orthanc_Monitoring(connexion); //Met la derniere ligne pour commencer le monitoring monitoring.autoSetChangeLastLine(); @@ -91,6 +95,12 @@ public void run() { monitoring.makeMonitor(); makeCD(monitoring.newStableStudyID); monitoring.clearAllList(); + try { + updateProgress(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @@ -120,16 +130,11 @@ public void makeCD(List newStableStudyID) { ConvertZipAction zipDownloader=new ConvertZipAction(connexion); Path file; try { - datenow=new Date(); - file = Files.createTempFile("CD_"+dateFormat.format(datenow) , ".zip"); - file.toFile().deleteOnExit(); - zipDownloader.setConvertZipAction(file.toString(), newStableStudyID.get(i), true); - //generate ZIP of DICOMs - zipDownloader.generateZip(true); - File zip=zipDownloader.getGeneratedZipFile(); - // Recuperation des donn�es patients - JSONParser parser=new JSONParser(); - JSONObject response=(JSONObject) parser.parse(connexion.makeGetConnectionAndStringBuilder("/studies/"+ newStableStudyID.get(i)).toString()); JSONObject mainPatientTag=(JSONObject) response.get("PatientMainDicomTags"); + //Store the Row number where we are going to display progress + int rownumber=table_burning_history.getRowCount(); + + JSONObject response=(JSONObject) parser.parse(connexion.makeGetConnectionAndStringBuilder("/studies/"+ newStableStudyID.get(i)).toString()); + JSONObject mainPatientTag=(JSONObject) response.get("PatientMainDicomTags"); //Get value of interest : Patient Name / ID / DOB / study date and description String nom=(String) mainPatientTag.get("PatientName"); @@ -139,6 +144,22 @@ public void makeCD(List newStableStudyID) { String studyDate=(String) mainDicomTag.get("StudyDate"); String studyDescription=(String) mainDicomTag.get("StudyDescription"); + //Update display status + (( DefaultTableModel) table_burning_history.getModel()).addRow(new String[]{nom,id, patientDOB ,studyDate,studyDescription,"Recieved" }); + + + datenow=new Date(); + file = Files.createTempFile("CD_"+dateFormat.format(datenow) , ".zip"); + file.toFile().deleteOnExit(); + zipDownloader.setConvertZipAction(file.toString(), newStableStudyID.get(i), true); + + table_burning_history.setValueAt("Retriving DICOMs", rownumber, 5); + + //generate ZIP of DICOMs + zipDownloader.generateZip(true); + File zip=zipDownloader.getGeneratedZipFile(); + + //Parse date and generate string in the date format set in the options by the user SimpleDateFormat parserDate = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat formatter = new SimpleDateFormat(dateFormatChoix); @@ -162,6 +183,7 @@ public void makeCD(List newStableStudyID) { if (studyDescription==null) studyDescription="N/A"; // Unzip du fichier ZIP recupere + table_burning_history.setValueAt("Unzipping", rownumber, 5); unzip(zip); @@ -183,17 +205,24 @@ public void makeCD(List newStableStudyID) { else { discType=suportType; } - + File robotRequestFile=null; // Creation du Cd if (burnerManifacturer.equals("Epson")) { //Generation du Dat File dat = printDat(nom, id, studyDate, studyDescription, patientDOBString); - createCdBurnerEpson(nom, id, formattedDateExamen, studyDescription, dat, discType); + robotRequestFile=createCdBurnerEpson(nom, id, formattedDateExamen, studyDescription, dat, discType); + + } else if(burnerManifacturer.equals("Primera")) { - createCdBurnerPrimera(nom, id, formattedDateExamen, studyDescription, patientDOBString, discType); + robotRequestFile=createCdBurnerPrimera(nom, id, formattedDateExamen, studyDescription, patientDOBString, discType); } + //Put the JDF base name associated to the Row number of the table for Monitoring + burningStatus.put(FilenameUtils.getBaseName(robotRequestFile.getAbsolutePath().toString()), new Object[] {rownumber, folder.toFile()}); + + table_burning_history.setValueAt("Sent to Burner", rownumber, 5); + //On efface tout a la sortie JVM recursiveDeleteOnExit(folder); //Efface le zip dezipe @@ -221,7 +250,7 @@ private void unzip(File zipFile){ //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); - textArea.append("Unzipping "); + while(ze!=null){ String fileName = ze.getName(); @@ -263,7 +292,7 @@ private void unzip(File zipFile){ * @param studyDescription * @param dat */ - private void createCdBurnerEpson(String nom, String id, String date, String studyDescription, File dat, String discType){ + private File createCdBurnerEpson(String nom, String id, String date, String studyDescription, File dat, String discType){ //REalisation du texte pour le Robot String txtRobot= "# Making data CD\n" @@ -291,7 +320,8 @@ private void createCdBurnerEpson(String nom, String id, String date, String stud pw.close(); } - textArea.append("Request Sent , Patient name "+nom+" id "+id+" date "+date+" study "+studyDescription+"\n"); + return f; + } /** @@ -302,7 +332,7 @@ private void createCdBurnerEpson(String nom, String id, String date, String stud * @param studyDescription * @param discType */ - private void createCdBurnerPrimera(String nom, String id, String date, String studyDescription, String patientDOB, String discType){ + private File createCdBurnerPrimera(String nom, String id, String date, String studyDescription, String patientDOB, String discType){ //Command Keys/Values for Primera Robot String txtRobot= "Copies = 1\n" + "DataImageType = UDF\n" @@ -319,7 +349,7 @@ private void createCdBurnerPrimera(String nom, String id, String date, String st If this key is not given then no printing will be performed. */ + "PrintLabel="+labelFile+"\n" - /* MergeField - This key specifies a �Merge� field for SureThing printing. + /* MergeField - This key specifies a merge field for SureThing printing. The print file specified within the JRQ must be a SureThing file, and it must have been designed with a Merge File specified. Fields should be specified in the correct order to match the SureThing design. @@ -342,8 +372,8 @@ private void createCdBurnerPrimera(String nom, String id, String date, String st } finally { pw.close(); } + return f; - textArea.append("Request Sent , Patient name "+nom+" id "+id+" date "+date+" study "+studyDescription+"\n"); } //Creer le fichier DAT pour injecter NOM, Date, Modalite @@ -375,6 +405,35 @@ private File printDat(String nom, String id, String date, String studyDescriptio pw.close(); } return dat; + } + + private void updateProgress() throws IOException { + File folder = new File(epsonDirectory); + File[] listOfFiles = folder.listFiles(); + + for (File file : listOfFiles) { + if (file.isFile()) { + String baseName=FilenameUtils.getBaseName(file.toString()); + if(burningStatus.containsKey(baseName)) { + String extension=FilenameUtils.getExtension(file.toString()); + int rowNubmer=(int) burningStatus.get(baseName)[0]; + File tempFolder=(File) burningStatus.get(baseName)[1]; + if(extension.equals("ERR")) { + table_burning_history.setValueAt("Burning Error", rowNubmer, 5); + FileUtils.deleteDirectory(tempFolder); + }else if(extension.equals("INP")) { + table_burning_history.setValueAt("Burning In Progress", rowNubmer, 5); + }else if(extension.equals("DON")) { + table_burning_history.setValueAt("Burning Done", rowNubmer, 5); + FileUtils.deleteDirectory(tempFolder); + } + } + } + } + + + + } /** diff --git a/src/org/petctviewer/orthanc/monitoring/Monitoring_GUI.java b/src/org/petctviewer/orthanc/monitoring/Monitoring_GUI.java index 3cddcc09..695f7ef4 100644 --- a/src/org/petctviewer/orthanc/monitoring/Monitoring_GUI.java +++ b/src/org/petctviewer/orthanc/monitoring/Monitoring_GUI.java @@ -44,10 +44,10 @@ import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import javax.swing.table.DefaultTableModel; -import javax.swing.text.DefaultCaret; import org.petctviewer.orthanc.ParametreConnexionHttp; import org.petctviewer.orthanc.query.Rest; +import javax.swing.ListSelectionModel; @SuppressWarnings("serial") public class Monitoring_GUI extends JFrame { @@ -60,7 +60,6 @@ public class Monitoring_GUI extends JFrame { //CD Burner Service private JButton btnStopMonitoring, btnStartMonitoring; - private JTextArea textAreaCD; private CD_Burner cdBurner; //Service Status in Main tab @@ -93,6 +92,7 @@ public class Monitoring_GUI extends JFrame { * @wbp.nonvisual location=-24,419 */ private JTable table; + private JTable table_burning_history; /** * Launch the application. */ @@ -180,17 +180,29 @@ public Monitoring_GUI(ParametreConnexionHttp parametre) { tabbedPane.addTab("CD-Burner", null, CD_Burner_Tab, null); - textAreaCD = new JTextArea(); - textAreaCD.setColumns(30); - textAreaCD.setAutoscrolls(true); - textAreaCD.setRows(5); - DefaultCaret caret = (DefaultCaret) textAreaCD.getCaret(); - caret.setUpdatePolicy(DefaultCaret.OUT_BOTTOM); CD_Burner_Tab.setLayout(new BorderLayout(0, 0)); JScrollPane scrollPane = new JScrollPane(); CD_Burner_Tab.add(scrollPane, BorderLayout.CENTER); - scrollPane.setViewportView(textAreaCD); + + table_burning_history = new JTable(); + table_burning_history.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + table_burning_history.setPreferredScrollableViewportSize(new Dimension(450, 200)); + table_burning_history.setModel(new DefaultTableModel( + new String[][] { + }, + new String[] { + "Name", "ID", "DOB", "Date", "Description", "Status" + } + ) { + Class[] columnTypes = new Class[] { + String.class, String.class, String.class, String.class, String.class, String.class + }; + public Class getColumnClass(int columnIndex) { + return columnTypes[columnIndex]; + } + }); + scrollPane.setViewportView(table_burning_history); JPanel panel = new JPanel(); CD_Burner_Tab.add(panel, BorderLayout.SOUTH); @@ -198,7 +210,7 @@ public Monitoring_GUI(ParametreConnexionHttp parametre) { btnStartMonitoring = new JButton("Start monitoring"); btnStartMonitoring.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - cdBurner=new CD_Burner(parametre, textAreaCD); + cdBurner=new CD_Burner(parametre, table_burning_history); cdBurner.setCDPreference(); //On ouvre le watcher dans un nouveau thread pour ne pas bloquer l'interface cdBurner.startCDMonitoring(); @@ -239,7 +251,6 @@ public void actionPerformed(ActionEvent arg0) { cdMonitoringStarted=false; jPrefer.putBoolean("CDMonitoringStarted", false); updateStatusLabel(); - textAreaCD.append("Monitoring Terminated \n"); btnStartMonitoring.setEnabled(true); btnStopMonitoring.setEnabled(false); diff --git a/src/org/petctviewer/orthanc/query/AutoQuery.java b/src/org/petctviewer/orthanc/query/AutoQuery.java index 0caacbaa..fe1eedb1 100644 --- a/src/org/petctviewer/orthanc/query/AutoQuery.java +++ b/src/org/petctviewer/orthanc/query/AutoQuery.java @@ -121,6 +121,7 @@ public String[] sendQuery(String name, String id, String dateFrom, String dateTo if (From==null && To==null) date="*";getClass(); //On lance la query if (StringUtils.equals(name, "*")==false || StringUtils.equals(id, "*")==false || StringUtils.equals(dateFrom, "*")==false || StringUtils.equals(dateTo, "*")==false || StringUtils.equals(modality, "*")==false || StringUtils.equals(studyDescription, "*")==false|| StringUtils.equals(accessionNumber, "*")==false) { + results=api.getQueryAnswerIndexes("Study", name , id, date, modality, studyDescription , accessionNumber, aet); } @@ -203,8 +204,15 @@ protected Date tenPM() { * @throws IOException */ protected void csvReading(File file, JTable table) throws IOException { + CSVFormat csvFileFormat = CSVFormat.EXCEL.withFirstRecordAsHeader().withIgnoreEmptyLines(); CSVParser csvParser=CSVParser.parse(file, StandardCharsets.UTF_8, csvFileFormat); + + //If only one column maybe French CSV with semi column Separator + if(csvParser.getHeaderMap().size()==1) { + CSVFormat csvFileFormatFrench = CSVFormat.EXCEL.withDelimiter(';').withFirstRecordAsHeader().withIgnoreEmptyLines(); + csvParser=CSVParser.parse(file, StandardCharsets.UTF_8, csvFileFormatFrench); + }; //On met les records dans une list List csvRecord=csvParser.getRecords(); // On balaie le fichier ligne par ligne diff --git a/src/org/petctviewer/orthanc/query/Rest.java b/src/org/petctviewer/orthanc/query/Rest.java index d1999320..f7112748 100644 --- a/src/org/petctviewer/orthanc/query/Rest.java +++ b/src/org/petctviewer/orthanc/query/Rest.java @@ -316,6 +316,7 @@ private String setQuery(String level, String name, String id, String studyDate, + "\"StudyDescription\" : \"" + studyDescription + "\"," + "\"AccessionNumber\" : \"" + accessionNumber + "\"}" + "}"; + System.out.println(query); return query; } diff --git a/src/org/petctviewer/orthanc/query/VueRest.java b/src/org/petctviewer/orthanc/query/VueRest.java index 44ccf131..21678890 100644 --- a/src/org/petctviewer/orthanc/query/VueRest.java +++ b/src/org/petctviewer/orthanc/query/VueRest.java @@ -707,7 +707,7 @@ public void actionPerformed(ActionEvent arg0) { table.putClientProperty("terminateEditOnFocusLost", true); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setModel(new DefaultTableModel(new Object[] {"Last Name", "First Name", "ID", "Accession Nb", "Study Date From","Study Date To", "Modality", "Study Description" },0)); - table.setToolTipText("Date Format YYYYMMDD, Modality example : CT//MRI"); + table.setToolTipText("Date Format YYYYMMDD, Modality example : CT\\\\MRI"); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); scrollPane.setViewportView(table);