Class JDialogAnonymizeDirectory.AnonymizeDicomDirectories

  • All Implemented Interfaces:
    java.lang.Runnable
    Enclosing class:
    JDialogAnonymizeDirectory

    public class JDialogAnonymizeDirectory.AnonymizeDicomDirectories
    extends java.lang.Thread
    This thread anonymization processes all the Dicom files in the submitted source directories and places them into the submitted destination directory. Note that these selected directories are processed serially.

    When one directory is chosen as the source, all anonymized Dicom files in source are placed directly in the destination. Any images in any subdirectories (when chkChildren is selected) are sent into the children of the sub-directories.

    More than one submitted source directory will be placed into discrete child directories of the submitted destination directory. As as example, /images/a, /images/b are selected, and /dest is the selected destination directory. They would get put into /dest/a, and /dest/b.

    Naming can change the way the destination is made. Selecting a top-level randomisation, will randomate the output directory ofthe selected image directory. This isalong the lines in the above example as /images/a becoming /dest/abcde; and /images/b becoming /dest/12345. Selecting only one input directory will notmakea difference for top-level randomising. Child-directory randomising will give a random name when processing child direcories. this amounts to selecting /images (and recursive processing) and the destination directory /dest,and getting /images/a becoming /dest/abcde, and /images/b becoming /dest/12345.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Constructor Summary

      Constructors 
      Constructor Description
      AnonymizeDicomDirectories​(java.io.File[] src, java.io.File dest, java.lang.String aname, int startseq, int toprand, boolean do_rename)
      sets up the anonymizer thread.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addProcessLoggingNotifier​(javax.swing.JTextArea jta)
      a list of JTextAreas to be notified when a change in the process/output log is made. this permits almost-real-time updates to output devices this method adds the selected list of JTextAreas to receieve the output logs.
      private boolean anonymizeImage​(java.io.File imageFile, java.io.File destinationDirectory, int[] randomSuffixList, int numberOfSuffices)
      actually does the grunt-work of reading the designaated image-file, anonymizing it, and writing the file to the deisgnated destination directory.
      private boolean exists​(int rnum, int[] rlist, int rnumptr)
      Checks for the existance of the number rnum in the unsorted array rlist.
      private java.lang.String generateAnonymousName()
      creates a string to use as a name out of the generic name, and the sequence.
      java.lang.String getKeyLog()
      provides the string key of translations between source filename and destination filename.
      java.lang.String getProcessLog()
      provides the string key of translations between source filename and destination filename.
      private java.util.Vector<FileDicomSQItem> getSequenceTags​(ModelImage image)  
      private void logWriting​(java.io.File f)
      convienience method to add the filename to the log-string.
      private void notifyProcessLogs​(java.lang.String logtext)
      called when an update is made to the output log, this method updates all the process logging JTextAreas.
      private void processMainDirectory​(java.io.File sourceDirectory, java.io.File destinationDirectory)
      opens top-level image directory. anonymizes the images in the top directory, when the class has been set to dig in recursively, anonymizes the top directories and calls openSubDirectory(...) to anonymize the files below.
      private void processSubDirectory​(java.io.File destParentDirectory, java.io.File sourceParentDirectory)
      traverses the directory, anonymizing as it goes. the child directories are named after the source child-directory, and attempted to traverse (by calling processSubDirectory(File dest, File src)).
      void run()
      Specified by Thread. processes each directory selected directory, pausing after processing each selected directory to allow other threads run.
      void setCheckChildren​(boolean chk)
      tells the anonymizer to check and anonymize the child directories of the selected source directories.
      void setFinishNotification​(JDialogAnonymizeDirectory jsa)
      no real need for complete listener capabilities, so this is to take its place.
      private void setGenericName​(java.lang.String aname, int seqStart)
      sets the genericname, and the start sequence to use when generating the anonymousname.
      void stopProcess()
      stopping a thread prematurely is a co-operative process where the Thread checks for a stop-flag periodically, and stops itself by coming to the end of its run() method early.
      private void writeToKey​(java.lang.String original, java.lang.String newKey)
      appends the original string, then two tabs then the newKey, followed by a newline to the keylog. old keylog is not overwritten.
      private void writeToLog​(java.lang.String anon_name)
      appends the name string, in between parens trailed by a colon.
      private void writeToLog​(java.lang.String logappendage, boolean completeString)
      Method to append the string to the log, adding a newline to the end, if requested, and appending a colon when not adding a newline.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • anonymousName

        private java.lang.String anonymousName
        DOCUMENT ME!
      • checkChildren

        private boolean checkChildren
        DOCUMENT ME!
      • destDirs

        private java.io.File[] destDirs
        DOCUMENT ME!
      • destStub

        private java.io.File destStub
        DOCUMENT ME!
      • doRename

        private boolean doRename
        DOCUMENT ME!
      • genericName

        private java.lang.String genericName
        portion of the file name for all anonymized images.
      • io

        private FileIO io
        DOCUMENT ME!
      • keyLog

        private java.lang.String keyLog
        DOCUMENT ME!
      • notifierList

        private java.util.Vector<javax.swing.JTextArea> notifierList
        DOCUMENT ME!
      • outputLog

        private java.lang.String outputLog
        DOCUMENT ME!
      • randomizeTopLevelDir

        private int randomizeTopLevelDir
        DOCUMENT ME!
      • sequence

        private int sequence
        DOCUMENT ME!
      • sequenceStart

        private int sequenceStart
        DOCUMENT ME!
      • srcDirs

        private java.io.File[] srcDirs
        DOCUMENT ME!
      • stopThreadRequest

        private boolean stopThreadRequest
        DOCUMENT ME!
    • Constructor Detail

      • AnonymizeDicomDirectories

        AnonymizeDicomDirectories​(java.io.File[] src,
                                  java.io.File dest,
                                  java.lang.String aname,
                                  int startseq,
                                  int toprand,
                                  boolean do_rename)
        sets up the anonymizer thread.
        Parameters:
        src - the list of directories to anonymize. this may be as large or as small as needed
        dest - the output directory. when the source-list lists but one file, the destination is the directory provided. If the list is more than one, then the destination is the root of the output directorues. How the output directories are named depends on the boolean, toprand.
        aname - the name to use for all images processed.
        startseq - number to start the sequence for all names in the sequence of anonymousnames.
        toprand - determines which directory to anonymize, if any. When processing a list of more than one source, the top-level directory can be randomized (as if the selected list were the image-directories themselves), or the first sub-directory level of directories (as if the selected directories had held lists of patient directories).
        • NO_RANDOM_NAMES indicates no directory names are to be changed.
        • RANDOM_DIRECTORY_NAME indicates the top-level is to be randomised,
        • RANDOM_SUBDIRECTORY_NAME indicates the first sub-directory level to be randomised.

        There is (true has??) no effect when only one level randomised.

        do_rename - DOCUMENT ME!
    • Method Detail

      • addProcessLoggingNotifier

        public void addProcessLoggingNotifier​(javax.swing.JTextArea jta)
        a list of JTextAreas to be notified when a change in the process/output log is made. this permits almost-real-time updates to output devices this method adds the selected list of JTextAreas to receieve the output logs.
        Parameters:
        jta - DOCUMENT ME!
      • getKeyLog

        public java.lang.String getKeyLog()
        provides the string key of translations between source filename and destination filename. The string is formatted with newlines and tabs seperating the filenames.
        Returns:
        String the translation Strin as formatted by the anonymizer
      • getProcessLog

        public java.lang.String getProcessLog()
        provides the string key of translations between source filename and destination filename. The string is formatted with newlines and tabs seperating the filenames.
        Returns:
        String the translation Strin as formatted by the anonymizer
      • run

        public void run()
        Specified by Thread. processes each directory selected directory, pausing after processing each selected directory to allow other threads run. Notifies the 'anonDialog' of completion.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • setCheckChildren

        public void setCheckChildren​(boolean chk)
        tells the anonymizer to check and anonymize the child directories of the selected source directories. Default is false;
        Parameters:
        chk - whether or not to check the child directories.
      • setFinishNotification

        public void setFinishNotification​(JDialogAnonymizeDirectory jsa)
        no real need for complete listener capabilities, so this is to take its place.
        Parameters:
        jsa - the anonimizer dialog to notify of the anonymization being complete
      • stopProcess

        public void stopProcess()
        stopping a thread prematurely is a co-operative process where the Thread checks for a stop-flag periodically, and stops itself by coming to the end of its run() method early. This co-operative method of premature Thread stop permits the Thread to close any open system resources it needed, and will use the natural death procedures.

        In this case, in order to accept death, the Thread must close its open files; it will then back out of its recursion.

      • anonymizeImage

        private boolean anonymizeImage​(java.io.File imageFile,
                                       java.io.File destinationDirectory,
                                       int[] randomSuffixList,
                                       int numberOfSuffices)
        actually does the grunt-work of reading the designaated image-file, anonymizing it, and writing the file to the deisgnated destination directory. Note that the anonymous-name is class-public. don't overwrite it! This method contains a list to all the random numbers used in making the image destination due to problems in making File.exists() work correctly without a SecurityManager. (haven't tried WITH a SecurityManager).
        Parameters:
        imageFile - a File that could be a DICOM image. Non-DICOM images should fail and simply return out of this method without another thought. DIMC images will be processed and saved into the destination directory.
        destinationDirectory - a File which is the directory where a processed DICOM image file will be saved.
        randomSuffixList - array of ints, which are filled from 0 to max lengh of an unsorted numbers. each of which becomes the random name for the file.
        numberOfSuffices - current number of used slots in randomSuffixList. not to be larger than randomSuffixList.length returns boolean if the given image file was properly written to the destination directory, this method returns true. false gets returned if the file either did not get written correctly (which would generate an exception), or if the file was non-DICOM, and was therefor ignored.
        Returns:
        DOCUMENT ME!
        Throws:
        java.lang.IllegalArgumentException - when destinationDirectory.isDirecrtory() returns false
      • exists

        private boolean exists​(int rnum,
                               int[] rlist,
                               int rnumptr)
        Checks for the existance of the number rnum in the unsorted array rlist. The elements of rlist exist from rlist[0] to rlist[rnumptr-1]. Of course, if rnumptr is greater than to rlist.length, an ArrayIndexOutOfBoundsException will be thrown. Check for it. This of course means that rnum is not in the full array. This method does not check the array against the length of the array, but rather the number of assigned members, because only a partially-full list would return unpredicatable results.
        Parameters:
        rnum - number we are interested in finding.
        rlist - unsorted array of integers at the bottom elements.
        rnumptr - index into the array to stop searching; also, indicates the number of elements with an assigned value.
        Returns:
        true when rnum is found between rlist[0] and rlist[rlistptr-1]. false when rnum is not in the array.
      • generateAnonymousName

        private java.lang.String generateAnonymousName()
        creates a string to use as a name out of the generic name, and the sequence. When processed, the anonymous name will be genericname_[seq]. the following name will be genericname_[seq+1].
        Returns:
        the anonymous name.
      • logWriting

        private void logWriting​(java.io.File f)
        convienience method to add the filename to the log-string.

        Appends a newline to the file.

        Parameters:
        f - -- file to note the conversion of the file to log.
      • notifyProcessLogs

        private void notifyProcessLogs​(java.lang.String logtext)
        called when an update is made to the output log, this method updates all the process logging JTextAreas.
        Parameters:
        logtext - DOCUMENT ME!
      • processMainDirectory

        private void processMainDirectory​(java.io.File sourceDirectory,
                                          java.io.File destinationDirectory)
        opens top-level image directory. anonymizes the images in the top directory, when the class has been set to dig in recursively, anonymizes the top directories and calls openSubDirectory(...) to anonymize the files below.
        Parameters:
        sourceDirectory - DOCUMENT ME!
        destinationDirectory - DOCUMENT ME!
      • processSubDirectory

        private void processSubDirectory​(java.io.File destParentDirectory,
                                         java.io.File sourceParentDirectory)
        traverses the directory, anonymizing as it goes. the child directories are named after the source child-directory, and attempted to traverse (by calling processSubDirectory(File dest, File src)).
        Parameters:
        destParentDirectory - parent directory is the parent directory tree for the destination;
        sourceParentDirectory - source name is the name of the source directory name
        See Also:
        JDialogAnonymizeDirectory#processSubDirectory(File, File)
      • setGenericName

        private void setGenericName​(java.lang.String aname,
                                    int seqStart)
        sets the genericname, and the start sequence to use when generating the anonymousname. When processed, the anonymous name will be genericname_[seq]. the following name will be genericname_[seq+1].
        Parameters:
        aname - the name to use for all images processed.
        seqStart - number to start the sequence for all names in the sequence of anonymousnames.
        See Also:
        JDialogAnonymizeDirectory#generateAnonymousName()
      • writeToKey

        private void writeToKey​(java.lang.String original,
                                java.lang.String newKey)
        appends the original string, then two tabs then the newKey, followed by a newline to the keylog. old keylog is not overwritten.
        Parameters:
        original - DOCUMENT ME!
        newKey - DOCUMENT ME!
      • writeToLog

        private void writeToLog​(java.lang.String anon_name)
        appends the name string, in between parens trailed by a colon. Eg., (anon_name:)". To be used before filtering the tags out of images (as those actions are logged in sequence.)
        Parameters:
        anon_name - DOCUMENT ME!
      • writeToLog

        private void writeToLog​(java.lang.String logappendage,
                                boolean completeString)
        Method to append the string to the log, adding a newline to the end, if requested, and appending a colon when not adding a newline. The log is not replaced by the incoming string.
        Parameters:
        logappendage - string to write to the log
        completeString - true writes a newline to the log. false makes this an unfinished string.