/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
- /*---------------------------------------------------------------
- * Copyright 2005 by the Radiological Society of North America
- *
- * This source software is released under the terms of the
- * RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
- *----------------------------------------------------------------*/
- package org.rsna.ctp.stdstages;
- import org.apache.log4j.Logger;
- import org.rsna.ctp.objects.DicomObject;
- import org.rsna.ctp.objects.FileObject;
- import org.rsna.ctp.pipeline.AbstractPipelineStage;
- import org.rsna.ctp.pipeline.Processor;
- import org.rsna.ctp.stdstages.anonymizer.AnonymizerStatus;
- import org.rsna.ctp.stdstages.anonymizer.dicom.DICOMCorrector;
- import org.rsna.util.FileUtil;
- import org.w3c.dom.Element;
- import java.io.File;
- /**
- * The DicomCorrector pipeline stage class.
- */
- public class DicomCorrector extends AbstractPipelineStage implements Processor, Scriptable {
- static final Logger logger = Logger.getLogger(DicomCorrector.class);
- File dicomScriptFile = null; //the DicomFilter script that determines whether to anonymize the object
- boolean quarantineUncorrectedMismatches = false;
- boolean logUncorrectedMismatches = false;
- /**
- * Construct the DicomCorrector PipelineStage.
- * @param element the XML element from the configuration file
- * specifying the configuration of the stage.
- */
- public DicomCorrector(Element element) {
- super(element);
- String dicomScript = element.getAttribute("dicomScript").trim();
- if (!dicomScript.equals("")) {
- dicomScriptFile = FileUtil.getFile(dicomScript, "examples/example-filter.script");
- }
- quarantineUncorrectedMismatches = element.getAttribute("quarantineUncorrectedMismatches").trim().toLowerCase().equals("yes");
- logUncorrectedMismatches = element.getAttribute("logUncorrectedMismatches").trim().toLowerCase().equals("yes");
- }
- //Implement the Scriptable interface
- /**
- * Get the script files.
- * @return the script files used by this stage.
- */
- @Override
- public File[] getScriptFiles() {
- return new File[] { dicomScriptFile, null, null };
- }
- /**
- * Process a DicomObject, correcting what can be corrected
- * and returning the processed object.
- * If the object is not a DicomObject, pass the object unmodified.
- * @param fileObject the object to process.
- * @return the processed FileObject.
- */
- @Override
- public FileObject process(FileObject fileObject) {
- lastFileIn = new File(fileObject.getFile().getAbsolutePath());
- lastTimeIn = System.currentTimeMillis();
- if (fileObject instanceof DicomObject) {
- //If there is a dicomScriptFile, use it to determine whether to anonymize
- if ((dicomScriptFile == null) || ((DicomObject)fileObject).matches(dicomScriptFile).getResult()) {
- //Okay, correct the object
- File file = fileObject.getFile();
- AnonymizerStatus status =
- DICOMCorrector.correct(file, file, quarantineUncorrectedMismatches, logUncorrectedMismatches);
- if (status.isOK()) {
- fileObject = FileObject.getInstance(file);
- }
- else if (status.isQUARANTINE()) {
- if (quarantine != null) quarantine.insert(fileObject);
- lastFileOut = null;
- lastTimeOut = System.currentTimeMillis();
- return null;
- }
- else if (status.isSKIP()) ; //keep the input object
- }
- }
- lastFileOut = new File(fileObject.getFile().getAbsolutePath());
- lastTimeOut = System.currentTimeMillis();
- return fileObject;
- }
- }