def validate_result()

in presidio-analyzer/presidio_analyzer/predefined_recognizers/au_medicare_recognizer.py [0:0]


    def validate_result(self, pattern_text: str) -> bool:
        """
        Validate the pattern logic e.g., by running checksum on a detected pattern.

        :param pattern_text: the text to validated.
        Only the part in text that was detected by the regex engine
        :return: A bool indicating whether the validation was successful.
        """
        # Pre-processing before validation checks
        text = self.__sanitize_value(pattern_text, self.replacement_pairs)
        medicare_list = [int(digit) for digit in text]

        # Set weights based on digit position
        weight = [1, 3, 7, 9, 1, 3, 7, 9]

        # Perform checksums
        sum_product = 0
        for i in range(8):
            sum_product += medicare_list[i] * weight[i]
        remainder = sum_product % 10
        if remainder == medicare_list[8]:
            result = True
        else:
            result = None
        return result