示例#1
0
    //Getting data back into DataTable
    public DataTable normalize()
    {
        DocumentGenerator DOCXGen  = new DOCXGenerator();
        DocumentGenerator JPGGen   = new JPGGenerator();
        DocumentGenerator DICOMGen = new DICOMGenerator();
        DataTable         patients = new DataTable();

        patients.Columns.Add("Id", typeof(int));
        patients.Columns.Add("Name", typeof(String));
        patients.Columns.Add("Surname", typeof(String));
        patients.Columns.Add("Gender", typeof(String));
        patients.Columns.Add("DateOfBirth", typeof(String));
        patients.Columns.Add("Profession", typeof(String));
        patients.Columns.Add("City", typeof(String));
        patients.Columns.Add("Address", typeof(String));
        patients.Columns.Add("PhoneNumber", typeof(String));
        patients.Columns.Add("PathForFiles", typeof(String));
        string[] table    = new string[patients.Columns.Count - 1];
        string[] cleared  = new string[patients.Columns.Count];
        string[] s        = null;
        bool     check    = true;
        Node     node     = root;
        int      iterator = 0;

        while (root.getCounter() > 0)
        {
            var row = patients.NewRow();
            do
            {
                if (node.getNodes()[iterator].getCounter() > 0)
                {
                    node.CounterMinusOne();
                    node = node.getNodes()[iterator];
                    int categ = node.getCategory();
                    if (check)
                    {
                        table[categ] += node.getSign();
                    }
                    else
                    {
                        table[categ] += "*";
                    }
                    iterator = 0;
                    if (node.isEnd())
                    {
                        node.CounterMinusOne();
                        table[table.Length - 1] = node.getFromStack();
                    }
                    if (node.getSign().Equals('*'))
                    {
                        check = false;
                    }
                }
                else
                {
                    iterator++;
                }
            } while (!node.isEnd());
            check      = true;
            iterator   = 0;
            node       = root;
            s          = table[table.Length - 1].Split(";");
            cleared[0] = s[0];
            cleared[9] = s[1];
            for (int i = 1; i < cleared.Length - 1; i++)
            {
                cleared[i] = table[i - 1].Trim('*') + "*";
            }
            row["Id"]           = int.Parse(cleared[0]);
            row["Name"]         = cleared[1];
            row["Surname"]      = cleared[2];
            row["Gender"]       = table[2];
            row["DateOfBirth"]  = cleared[4];
            row["Profession"]   = cleared[5];
            row["City"]         = cleared[6];
            row["Address"]      = cleared[7];
            row["PhoneNumber"]  = cleared[8];
            row["PathForFiles"] = cleared[9];
            if (patients.Rows.Count < 100)
            {
                string sex = "M";
                if (table[2].Equals('K'))
                {
                    sex = "F";
                }
                Patient patient = new Patient(cleared[0], cleared[1], cleared[2], cleared[8], cleared[7], sex, cleared[5],
                                              cleared[6], cleared[4]);
                row["PathForFiles"] = JPGGen.generateDocument(patient) + ";" + DICOMGen.generateDocument(patient) + ";" + DOCXGen.generateDocument(patient);
            }
            table   = new string[patients.Columns.Count - 1];
            cleared = new string[patients.Columns.Count];

            s = null;


            patients.Rows.Add(row);
        }
        patients.DefaultView.Sort = "Id";

        return(patients);
    }
示例#2
0
        private void RunAlgorithm_Button_Click(object sender, RoutedEventArgs e)
        {
            bool k_anonimization      = RButton1KAnoAlgorithm.IsChecked == null ? false : RButton1KAnoAlgorithm.IsChecked == true ? true : false;
            bool k_alfa_anonimization = RButton1KAlfaAnoAlgorithm.IsChecked == null ? false : RButton1KAlfaAnoAlgorithm.IsChecked == true ? true : false;

            if (patientDataGenerated == null || patientDataGenerated.Rows.Count == 0)
            {
                promptUser("Patient data is empty.");
            }
            else if (k_anonimization)
            {
                try
                {
                    int k      = 0;
                    var k_text = kValue.Text;
                    Int32.TryParse(k_text, out k);
                    kValue.Text = "";
                    if (k > 2 && k < 21)
                    {
                        var anonimizator = new Anonymization();
                        var anonymized   = anonimizator.AnonymizeData(patientDataGenerated, k);

                        DocumentGenerator JPG_gen   = new JPGGenerator();
                        DocumentGenerator DICOM_gen = new DICOMGenerator();
                        DocumentGenerator DOCX_gen  = new DOCXGenerator();
                        List <ZPI_Projekt_Anonimizator.entity.Patient> dataBasePatients = new List <ZPI_Projekt_Anonimizator.entity.Patient>();
                        List <string> pathes = new List <string>();


                        foreach (DataRow row in anonymized.Rows)
                        {
                            var     values = row.ItemArray;
                            Patient p      = new Patient(values[0] + "", values[1] + "", values[2] + "", values[8] + "", values[7] + "", values[3] + "", values[5] + "", values[6] + "", values[4] + "");
                            dataBasePatients.Add(p);

                            if (!values[9].Equals(""))
                            {
                                string s = JPG_gen.generateDocument(p) + ";" + DICOM_gen.generateDocument(p) + ";" + DOCX_gen.generateDocument(p);
                                row.BeginEdit();
                                row[9] = s;
                                pathes.Add(s);
                            }
                            else
                            {
                                pathes.Add("");
                            }
                        }
                        anonymized.AcceptChanges();


                        XDocument xdoc = new XDocument(
                            new XDeclaration("1.0", "utf-8", "yes"),

                            new XElement("Patients",
                                         from patient in dataBasePatients
                                         select
                                         new XElement("Patient", new XElement("Id", patient.Id),
                                                      new XElement("Name", patient.Name),
                                                      new XElement("Surname", patient.SurName),
                                                      new XElement("Gender", patient.Gender),
                                                      new XElement("DateOfBirth", patient.DateOfBirth),
                                                      new XElement("Profession", patient.Profession),
                                                      new XElement("City", patient.City),
                                                      new XElement("Address", patient.Address),
                                                      new XElement("PhoneNumber", patient.PhoneNumber),
                                                      new XElement("PathForFiles", pathes[Int32.Parse(patient.Id) - 1])
                                                      )));

                        string path = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"/resource/XML_files/" + "anonymized_data" + ".xml";
                        xdoc.Save(path);

                        XMLAfterAnonimizationGrid.DataContext = anonymized.DefaultView;
                        XMLAfterAnonimizationGrid.Visibility  = Visibility.Visible;
                    }
                    else
                    {
                        promptUser("K has to be in range <3,20>");
                    }
                }
                catch (Exception ex)
                {
                    promptUser("Algoritm execution resulted in an error.");
                }
            }
            else if (k_alfa_anonimization)
            {
                try
                {
                    int k      = 0;
                    var k_text = kValue.Text;
                    Int32.TryParse(k_text, out k);
                    kValue.Text = "";
                    if (k > 2 && k < 21)
                    {
                        var anonimizator = new KAnonymization();
                        anonimizator.add(patientDataGenerated, k);
                        var anonymized = anonimizator.normalize();

                        List <ZPI_Projekt_Anonimizator.entity.Patient> dataBasePatients = new List <ZPI_Projekt_Anonimizator.entity.Patient>();
                        List <string> pathes = new List <string>();


                        foreach (DataRow row in anonymized.Rows)
                        {
                            var     values = row.ItemArray;
                            Patient p      = new Patient(values[0] + "", values[1] + "", values[2] + "", values[8] + "", values[7] + "", values[3] + "", values[5] + "", values[6] + "", values[4] + "");
                            dataBasePatients.Add(p);

                            if (!values[9].Equals(""))
                            {
                                pathes.Add(row[9] + "");
                            }
                            else
                            {
                                pathes.Add("");
                            }
                        }
                        anonymized.AcceptChanges();


                        XDocument xdoc = new XDocument(
                            new XDeclaration("1.0", "utf-8", "yes"),

                            new XElement("Patients",
                                         from patient in dataBasePatients
                                         select
                                         new XElement("Patient", new XElement("Id", patient.Id),
                                                      new XElement("Name", patient.Name),
                                                      new XElement("Surname", patient.SurName),
                                                      new XElement("Gender", patient.Gender),
                                                      new XElement("DateOfBirth", patient.DateOfBirth),
                                                      new XElement("Profession", patient.Profession),
                                                      new XElement("City", patient.City),
                                                      new XElement("Address", patient.Address),
                                                      new XElement("PhoneNumber", patient.PhoneNumber),
                                                      new XElement("PathForFiles", pathes[Int32.Parse(patient.Id) - 1])
                                                      )));

                        string path = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"/resource/XML_files/" + "anonymized2_data" + ".xml";
                        xdoc.Save(path);

                        XMLAfterAnonimizationGrid.DataContext = anonymized.DefaultView;
                        XMLAfterAnonimizationGrid.Visibility  = Visibility.Visible;
                    }
                    else
                    {
                        promptUser("K has to be in range <3,20>");
                    }
                }
                catch (Exception ex)
                {
                    promptUser("Algoritm execution resulted in an error.");
                }
            }
            else
            {
                promptUser("One of algorithms must be selected.");
            }
        }