/*
 * ARX: Powerful Data Anonymization
 * Copyright 2012 - 2017 Fabian Prasser, Florian Kohlmayer and contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.deidentifier.arx.risk;

/**
 * Provides information about the occurrence of an HIPPA identifier
 * 
 * @author David Gassmann
 * @author Fabian Prasser
 * @author Florian Kohlmayer
 */
public class HIPAAIdentifierMatch {
    
    /**
     * Represents the HIPPA identifiers
     * 
     * @author David Gassmann
     * @author Fabian Prasser
     * @author Florian Kohlmayer
     */
    public enum HIPAAIdentifier {
                                 NAME('A'),
                                 GEOGRAPHIC_SUBDIVISION('B'),
                                 DATE('C'),
                                 TELEPHONE_NUMBER('D'),
                                 FAX_NUMBER('E'),
                                 EMAIL_ADDRESS('F'),
                                 SOCIAL_SECURITY_NUMBER('G'),
                                 MEDICAL_RECORD_NUMBER('H'),
                                 HEALTH_PLAN_BENEFICIARY_NUMBER('I'),
                                 ACCOUNT_NUMBER('J'),
                                 CERTIFICATE_NUMBER('K'),
                                 VEHICLE_IDENTIFIER('L'),
                                 DEVICE_IDENTIFIER('M'),
                                 URL('N'),
                                 IP('O'),
                                 BIOMETRIC_IDENTIFIER('P'),
                                 PHOTOGRAPH('Q'),
                                 OTHER('R');
                                 
        private final char category;
        
        HIPAAIdentifier(char category) {
            this.category = category;
        }
    }
    
    /**
     * Represents the classifier for the HIPAA identifier.
     * @author David Gassmann
     * @author Fabian Prasser
     * @author Florian Kohlmayer
     */
    public enum MatchType {ATTRIBUTE_NAME,
                           ATTRIBUTE_VALUE
    }
    
    /** Field */
    private final String          column;
    /** Field */
    private final HIPAAIdentifier identifier;
    /** Field */
    private final MatchType       matchType;
    /** Field */
    private final String          value;
    /** Field */
    private final String          instance;
    
    /**
     * Constructor.
     * 
     * @param column
     * @param identifier
     * @param type
     * @param value
     */
    HIPAAIdentifierMatch(String column, HIPAAIdentifier identifier, String instance, MatchType type, String value) {
        this.column = column;
        this.matchType = type;
        this.identifier = identifier;
        this.value = value;
        this.instance = instance;
    }
    
    /**
     * The column name where the identifier was found
     * @return The column name
     */
    public String getColumn() {
        return column;
    }
    
    /**
     * The confidence of the discovery, or null if the
     * match type is ATTRIBUTE_NAME
     * 
     * @return The value which caused the warning
     */
    public Double getConfidence() {
        try {
            return Double.valueOf(value);
        } catch (Exception e) {
            return null;
        }
    }
    
    /**
     * The identifier which was found
     * @return The found identifier
     */
    public HIPAAIdentifier getIdentifier() {
        return identifier;
    }
    
    /**
     * The instance of the identifier
     * @return
     */
    public String getInstance() {
        return instance;
    }
    
    /**
     * The classifier (column name or instance)
     * @return
     */
    public MatchType getMatchType() {
        return matchType;
    }

    /**
     * The value which caused the identification
     * @return The value which caused the warning
     */
    public String getValue() {
        if (getConfidence() != null) {
            return null;
        } else {
            return value;
        }
    }
    
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("HIPAAIdentifierMatch {\n");
        builder.append(" - Column: ").append(getColumn()).append("\n");
        builder.append(" - Identifier: ").append(getIdentifier()).append("\n");
        builder.append(" - Instance: ").append(getInstance()).append("\n");
        builder.append(" - Match type: ").append(getMatchType()).append("\n");
        builder.append(" - Value: ").append(getValue()).append("\n");
        builder.append("}");
        return builder.toString();
    }
}

@@ -1108,131 +1108,46 @@
     
-                         NAME('A'),%0A                                 GEOGRAPHIC_SUBDIVISION('B'),%0A                         
+NAME,%0A        GEOGRAPHIC_SUBDIVISION,%0A
     
@@ -1158,40 +1158,10 @@
 DATE
-('C')
 ,%0A
-                         
     
@@ -1184,13 +1184,8 @@
 MBER
-('D')
 ,%0A  
@@ -1194,75 +1194,20 @@
     
-                         FAX_NUMBER('E'),%0A                         
+FAX_NUMBER,%0A
     
@@ -1227,40 +1227,10 @@
 RESS
-('F')
 ,%0A
-                         
     
@@ -1259,13 +1259,8 @@
 MBER
-('G')
 ,%0A  
@@ -1269,86 +1269,31 @@
     
-                         MEDICAL_RECORD_NUMBER('H'),%0A                         
+MEDICAL_RECORD_NUMBER,%0A
     
@@ -1330,40 +1330,10 @@
 MBER
-('I')
 ,%0A
-                         
     
@@ -1354,13 +1354,8 @@
 MBER
-('J')
 ,%0A  
@@ -1364,83 +1364,28 @@
     
-                         CERTIFICATE_NUMBER('K'),%0A                         
+CERTIFICATE_NUMBER,%0A
     
@@ -1410,40 +1410,10 @@
 FIER
-('L')
 ,%0A
-                         
     
@@ -1437,13 +1437,8 @@
 FIER
-('M')
 ,%0A  
@@ -1447,110 +1447,25 @@
     
-                         URL('N'),%0A                                 IP('O'),%0A                         
+URL,%0A        IP,%0A
     
@@ -1492,40 +1492,10 @@
 FIER
-('P')
 ,%0A
-                         
     
@@ -1512,13 +1512,8 @@
 RAPH
-('Q')
 ,%0A  
@@ -1522,213 +1522,14 @@
     
-                         OTHER('R');%0A                                 %0A        private final char category;%0A        %0A        HIPAAIdentifier(char category) %7B%0A            this.category = category;%0A        %7D
+OTHER;
 %0A   
@@ -1731,16 +1731,25 @@
 chType %7B
+%0A        
 ATTRIBUT
@@ -1756,35 +1756,16 @@
 E_NAME,%0A
-                   
         

Remove more redundant code