LaurelBridge.DCF.Examples.Filter Namespace
LAUREL BRIDGE

LaurelBridge.DCF.Examples.Filter Namespace

DICOM Connectivity Framework V3.4
The Filter example demonstrates how DCF builds and executes filters.
Classes

  ClassDescription
Public classProgram
Simple Filter example to demonstrate filtering DICOM datasets.
Examples

Filter Sample Code
public class Program
{
    private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

    /// <summary>
    /// Main entry point for Filter.
    /// </summary>
    [STAThread]
    public static void Main()
    {
        try
        {
            FilterPatientName();
            FindReplaceTagAction();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught during execution: {0}", e);
        }

        if (System.Diagnostics.Debugger.IsAttached)
        {
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey();
        }
    }

    /// <summary>
    /// Changes the example dataset 'mr-knee.dcm' patient name using a DicomElementFilter.
    /// </summary>
    private static void FilterPatientName()
    {
        // [ filter_config ]
        // filter_type = DICOM_ELEMENT_FILTER
        // filter_sub_type = unknown
        // create_original_attributes_seq = TRUE
        // 
        // [ filter_config/elements_to_match ]
        // 0010,0010 = MINER^STEPHEN
        // 0008,0060 = MR
        // 
        // [ filter_config/elements_to_replace ]
        // 0010,0010 = Doe^John

        CFGGroup cfg = new CFGGroup("filter_config");
        cfg.addAttribute(new CFGAttribute("filter_type", "DICOM_ELEMENT_FILTER"));
        cfg.addAttribute(new CFGAttribute("filter_sub_type", "unknown"));
        cfg.addAttribute(new CFGAttribute("create_original_attributes_seq", "TRUE"));

        CFGGroup elementsToMatchGroup = new CFGGroup("elements_to_match");
        elementsToMatchGroup.addAttribute(new CFGAttribute("0010,0010", "MINER^STEPHEN"));
        elementsToMatchGroup.addAttribute(new CFGAttribute("0008,0060", "MR"));
        cfg.addGroup(elementsToMatchGroup);

        CFGGroup elementsToReplace = new CFGGroup("elements_to_replace");
        elementsToReplace.addAttribute(new CFGAttribute("0010,0010", "Doe^John"));
        cfg.addGroup(elementsToReplace);

        Logger.InfoFormat("Filter Patient's Name Configuration:{0}{1}", Environment.NewLine, cfg);

        using (DicomFileInput dfi = new DicomFileInput("mr-knee.dcm"))
        {
            IDicomInput di = DicomFilterFactory.Instance().CreateFilter(dfi, cfg, new DicomSessionSettings());
            DicomDataSet ds = di.ReadDataSet();
            Logger.InfoFormat("Filtered Dataset:{0}{1}", Environment.NewLine, ds);
        }
    }

    /// <summary>
    /// Performs a Find/Replace operation on the original tag value using a FilterAction.
    /// </summary>
    private static void FindReplaceTagAction()
    {
        // [ data ]
        // tag = 0010,0010
        // find = (.*)\^.*$
        // replace = $1^JOHN
        // regex = true
        // ignore_case = false

        CFGGroup cfg = new CFGGroup("data");
        cfg.addAttribute(new CFGAttribute(DCF.Filters.FindReplaceTagAction.CFG_TAG, "0010,0010"));
        cfg.addAttribute(new CFGAttribute(DCF.Filters.FindReplaceTagAction.CFG_FIND, @"(.*)\^.*$"));
        cfg.addAttribute(new CFGAttribute(DCF.Filters.FindReplaceTagAction.CFG_REPLACE, "$1^JOHN"));
        cfg.addAttribute(new CFGAttribute(DCF.Filters.FindReplaceTagAction.CFG_REGEX, "true"));
        cfg.addAttribute(new CFGAttribute(DCF.Filters.FindReplaceTagAction.CFG_IGNORE_CASE, "false"));

        Logger.InfoFormat("Find/Replace TagAction Configuration:{0}{1}", Environment.NewLine, cfg);

        using (DicomFileInput dfi = new DicomFileInput("mr-knee.dcm"))
        {
            DicomDataSet ds = dfi.ReadDataSetNoPixels();
            FindReplaceTagAction action = new FindReplaceTagAction();
            List<string> tagsModified = new List<string>();
            action.ApplyAction(cfg, new DicomSessionSettings(), delegate(string s) { tagsModified.Add(s); }, ref ds);
            Logger.InfoFormat("Find/Replace Filtered Dataset:{0}{1}", Environment.NewLine, ds);
            Logger.InfoFormat("Tags Modified:{0}{1}", Environment.NewLine, tagsModified[0]);
        }
    }