<commit_before>﻿/* Filename:    RemoveHL7Item.cs
 * 
 * Author:      <NAME> (<EMAIL>) 
 *              
 * Credits:     Code to handle the Path and LiteralPath parameter sets, and expansion of wildcards is based
 *              on Oisin Grehan's post: http://www.nivot.org/blog/post/2008/11/19/Quickstart1ACmdletThatProcessesFilesAndDirectories
 * 
 * Date:        30/08/2016
 * 
 * Notes:       Implements the cmdlet to update the value of a specific item from a HL7 v2 message.
 * 
 */

namespace HL7Tools
{
    using System;
    using System.Collections.Generic;
    using System.IO;
	using System.Text;
    using System.Linq;
    using System.Management.Automation;

    // CmdLet: Remove-HL7Item
    // Removes the value of a specific item from the message 
    [Cmdlet(VerbsCommon.Remove, "HL7Item", SupportsShouldProcess = true)]
    public class RemoveHL7Item : PSCmdlet
    {
        private string[] itemPosition;
        private string[] paths;
        private bool expandWildcards = false;
        private string[] filter = new string[] { };
        private bool filterConditionsMet = true;
        private bool allrepeats;
		private string encoding = "UTF-8";

        // Parameter set for the -Path and -LiteralPath parameters. A parameter set ensures these options are mutually exclusive.
        // A LiteralPath is used in situations where the filename actually contains wild card characters (eg File[1-10].txt) and you want
        // to use the literaral file name instead of treating it as a wildcard search.
        [Parameter(
            Mandatory = true,
            ValueFromPipeline = false,
            ValueFromPipelineByPropertyName = true,
            ParameterSetName = "Literal")
        ]
        [Alias("PSPath", "Name", "Filename")]
        [ValidateNotNullOrEmpty]
        public string[] LiteralPath
        {
            get { return this.paths; }
            set { this.paths = value; }
        }

        [Parameter(
            Position = 0,
            Mandatory = true,
            ValueFromPipeline = true,
            ValueFromPipelineByPropertyName = true,
            ParameterSetName = "Path")

        ]
        [ValidateNotNullOrEmpty]

        public string[] Path
        {
            get { return this.paths; }
            set
            {
                this.expandWildcards = true;
                this.paths = value;
            }
        }

        //  A parameter for position of the item to remove
        [Parameter(
            Mandatory = true,
            Position = 1,
            HelpMessage = "Position of the item to return, e.g. PID-3.1"
        )]
        [Alias("Item")]
        public string[] ItemPosition
        {
            get { return this.itemPosition; }
            set { this.itemPosition = value; }
        }


        // Parameter to optionally filter the messages based on matching message contents
        [Parameter(
            Mandatory = false,
            Position = 2,
            HelpMessage = "Filter on message contents")]
        public string[] Filter
        {
            get { return this.filter; }
            set { this.filter = value; }
        }

        // Do not wait for ACKs responses if this switch is set
        [Parameter(
            Mandatory = false,
            HelpMessage = "Update all repeats of an item"
         )]
        public SwitchParameter RemoveAllRepeats
        {
            get { return this.allrepeats; }
            set { this.allrepeats = value; }
        }

        // Parameter to optionally filter the messages based on matching message contents
        [Parameter(
            Mandatory = false,
            Position = 3,
            HelpMessage = "Text encoding ('UTF-8' | 'ISO-8859-1'")]
        [ValidateSet("UTF-8", "ISO-8859-1")]
        public string Encoding
        {
            get { return this.encoding; }
            set { this.encoding = value; }
        }

        /// <summary>
        /// get the HL7 item provided via the cmdlet parameter HL7ItemPosition
        /// </summary>
        protected override void ProcessRecord()
        {

            // validate the that all of the list of locations to remove are valid.<commit_msg>Added -Encoding parameter. Now supports ISO-8559-1 messages (default is still UTF-8)<commit_after>﻿/* Filename:    RemoveHL7Item.cs
 * 
 * Author:      <NAME> (<EMAIL>) 
 *              
 * Credits:     Code to handle the Path and LiteralPath parameter sets, and expansion of wildcards is based
 *              on <NAME>'s post: http://www.nivot.org/blog/post/2008/11/19/Quickstart1ACmdletThatProcessesFilesAndDirectories
 * 
 * Date:        30/08/2016
 * 
 * Notes:       Implements the cmdlet to update the value of a specific item from a HL7 v2 message.
 * 
 */

namespace HL7Tools
{
    using System;
    using System.Collections.Generic;
    using System.IO;
	using System.Text;
    using System.Linq;
    using System.Management.Automation;

    // CmdLet: Remove-HL7Item
    // Removes the value of a specific item from the message 
    [Cmdlet(VerbsCommon.Remove, "HL7Item", SupportsShouldProcess = true)]
    public class RemoveHL7Item : PSCmdlet
    {
        private string[] itemPosition;
        private string[] paths;
        private bool expandWildcards = false;
        private string[] filter = new string[] { };
        private bool filterConditionsMet = true;
        private bool allrepeats;
		private string encoding = "UTF-8";

        // Parameter set for the -Path and -LiteralPath parameters. A parameter set ensures these options are mutually exclusive.
        // A LiteralPath is used in situations where the filename actually contains wild card characters (eg File[1-10].txt) and you want
        // to use the literaral file name instead of treating it as a wildcard search.
        [Parameter(
            Mandatory = true,
            ValueFromPipeline = false,
            ValueFromPipelineByPropertyName = true,
            ParameterSetName = "Literal")
        ]
        [Alias("PSPath", "Name", "Filename")]
        [ValidateNotNullOrEmpty]
        public string[] LiteralPath
        {
            get { return this.paths; }
            set { this.paths = value; }
        }

        [Parameter(
            Position = 0,
            Mandatory = true,
            ValueFromPipeline = true,
            ValueFromPipelineByPropertyName = true,
            ParameterSetName = "Path")

        ]
        [ValidateNotNullOrEmpty]

        public string[] Path
        {
            get { return this.paths; }
            set
            {
                this.expandWildcards = true;
                this.paths = value;
            }
        }

        //  A parameter for position of the item to remove
        [Parameter(
            Mandatory = true,
            Position = 1,
            HelpMessage = "Position of the item to return, e.g. PID-3.1"
        )]
        [Alias("Item")]
        public string[] ItemPosition
        {
            get { return this.itemPosition; }
            set { this.itemPosition = value; }
        }


        // Parameter to optionally filter the messages based on matching message contents
        [Parameter(
            Mandatory = false,
            Position = 2,
            HelpMessage = "Filter on message contents")]
        public string[] Filter
        {
            get { return this.filter; }
            set { this.filter = value; }
        }

        // Do not wait for ACKs responses if this switch is set
        [Parameter(
            Mandatory = false,
            HelpMessage = "Update all repeats of an item"
         )]
        public SwitchParameter RemoveAllRepeats
        {
            get { return this.allrepeats; }
            set { this.allrepeats = value; }
        }

        // Parameter to specify the message character encoding format
        [Parameter(
            Mandatory = false,
            Position = 3,
            HelpMessage = "Text encoding ('UTF-8' | 'ISO-8859-1'")]
        [ValidateSet("UTF-8", "ISO-8859-1")]
        public string Encoding
        {
            get { return this.encoding; }
            set { this.encoding = value; }
        }

        /// <summary>
        /// get the HL7 item provided via the cmdlet parameter HL7ItemPosition
        /// </summary>
        protected override void ProcessRecord()
        {

            // validate the that all of the list of locations to remove are valid.
{'fraction_non_alphanumeric': 0.08249258160237388, 'fraction_numerical': 0.012106824925816023, 'mean_word_length': 1.741054001301236, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5905542', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2127, 'n_words': 715}