Ejemplo n.º 1
0
        public void CanBeCanceledBy_FirstAnonimizationFor100Records_ReturnsWrongValue()
        {
            path      = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"\resource\XML_files\test100.xml";
            dataTable = XMLParser.parseDocument(path);
            anon.add(dataTable, 2);
            var           anonDataTable = anon.normalize();
            List <string> userArr       = new List <string>();

            for (int i = 0; i < anonDataTable.Rows.Count; i++)
            {
                userArr.Add(anonDataTable.Rows[i][1].ToString() + anonDataTable.Rows[i][2].ToString() + anonDataTable.Rows[i][3].ToString() + anonDataTable.Rows[i][4].ToString() + anonDataTable.Rows[i][5].ToString() + anonDataTable.Rows[i][6].ToString());
            }
            Dictionary <string, int> dict = new Dictionary <string, int>();

            foreach (string item in userArr)
            {
                if (!dict.ContainsKey(item))
                {
                    dict.Add(item, 1);
                }
                else
                {
                    int count = 0;
                    dict.TryGetValue(item, out count);
                    dict.Remove(item);
                    dict.Add(item, count + 1);
                }
            }

            Assert.IsTrue(!dict.ContainsValue(1));
        }
Ejemplo n.º 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.");
            }
        }