/src/main/java/org/rsna/ctp/stdstages/DicomCorrector.java

https://github.com/blezek/Notion · Java · 99 lines · 55 code · 16 blank · 28 comment · 12 complexity · bb471b4b4bc97892724c4f17a4ca003f MD5 · raw file

  1. /*---------------------------------------------------------------
  2. * Copyright 2005 by the Radiological Society of North America
  3. *
  4. * This source software is released under the terms of the
  5. * RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
  6. *----------------------------------------------------------------*/
  7. package org.rsna.ctp.stdstages;
  8. import org.apache.log4j.Logger;
  9. import org.rsna.ctp.objects.DicomObject;
  10. import org.rsna.ctp.objects.FileObject;
  11. import org.rsna.ctp.pipeline.AbstractPipelineStage;
  12. import org.rsna.ctp.pipeline.Processor;
  13. import org.rsna.ctp.stdstages.anonymizer.AnonymizerStatus;
  14. import org.rsna.ctp.stdstages.anonymizer.dicom.DICOMCorrector;
  15. import org.rsna.util.FileUtil;
  16. import org.w3c.dom.Element;
  17. import java.io.File;
  18. /**
  19. * The DicomCorrector pipeline stage class.
  20. */
  21. public class DicomCorrector extends AbstractPipelineStage implements Processor, Scriptable {
  22. static final Logger logger = Logger.getLogger(DicomCorrector.class);
  23. File dicomScriptFile = null; //the DicomFilter script that determines whether to anonymize the object
  24. boolean quarantineUncorrectedMismatches = false;
  25. boolean logUncorrectedMismatches = false;
  26. /**
  27. * Construct the DicomCorrector PipelineStage.
  28. * @param element the XML element from the configuration file
  29. * specifying the configuration of the stage.
  30. */
  31. public DicomCorrector(Element element) {
  32. super(element);
  33. String dicomScript = element.getAttribute("dicomScript").trim();
  34. if (!dicomScript.equals("")) {
  35. dicomScriptFile = FileUtil.getFile(dicomScript, "examples/example-filter.script");
  36. }
  37. quarantineUncorrectedMismatches = element.getAttribute("quarantineUncorrectedMismatches").trim().toLowerCase().equals("yes");
  38. logUncorrectedMismatches = element.getAttribute("logUncorrectedMismatches").trim().toLowerCase().equals("yes");
  39. }
  40. //Implement the Scriptable interface
  41. /**
  42. * Get the script files.
  43. * @return the script files used by this stage.
  44. */
  45. @Override
  46. public File[] getScriptFiles() {
  47. return new File[] { dicomScriptFile, null, null };
  48. }
  49. /**
  50. * Process a DicomObject, correcting what can be corrected
  51. * and returning the processed object.
  52. * If the object is not a DicomObject, pass the object unmodified.
  53. * @param fileObject the object to process.
  54. * @return the processed FileObject.
  55. */
  56. @Override
  57. public FileObject process(FileObject fileObject) {
  58. lastFileIn = new File(fileObject.getFile().getAbsolutePath());
  59. lastTimeIn = System.currentTimeMillis();
  60. if (fileObject instanceof DicomObject) {
  61. //If there is a dicomScriptFile, use it to determine whether to anonymize
  62. if ((dicomScriptFile == null) || ((DicomObject)fileObject).matches(dicomScriptFile).getResult()) {
  63. //Okay, correct the object
  64. File file = fileObject.getFile();
  65. AnonymizerStatus status =
  66. DICOMCorrector.correct(file, file, quarantineUncorrectedMismatches, logUncorrectedMismatches);
  67. if (status.isOK()) {
  68. fileObject = FileObject.getInstance(file);
  69. }
  70. else if (status.isQUARANTINE()) {
  71. if (quarantine != null) quarantine.insert(fileObject);
  72. lastFileOut = null;
  73. lastTimeOut = System.currentTimeMillis();
  74. return null;
  75. }
  76. else if (status.isSKIP()) ; //keep the input object
  77. }
  78. }
  79. lastFileOut = new File(fileObject.getFile().getAbsolutePath());
  80. lastTimeOut = System.currentTimeMillis();
  81. return fileObject;
  82. }
  83. }