extractor: improve rules for extracting aadhar by verifying checksum
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s

This commit is contained in:
androidlover5842
2026-01-31 10:16:20 +05:30
parent 12d1327525
commit 9299d22c5b
2 changed files with 16 additions and 2 deletions

View File

@@ -240,6 +240,7 @@ class DocumentExtractionService(
normalizePinCode(results)
normalizeIdNumber(results)
markAadhaarIfValid(results)
results["docType"] = computeDocType(results, handled)
applyGuestUpdates(document, propertyId, results)
return ExtractionResult(results, handled)
@@ -265,7 +266,7 @@ class DocumentExtractionService(
val fromAddress = extractPinFromAddress(address)
val chosen = fromPin ?: fromAddress
results[pinKey] = chosen ?: "NONE"
results[pinKey] = if (isValidPin(chosen)) chosen!! else "NONE"
}
private fun normalizeIdNumber(results: MutableMap<String, String>) {
@@ -277,6 +278,14 @@ class DocumentExtractionService(
}
}
private fun markAadhaarIfValid(results: MutableMap<String, String>) {
val idKey = DocumentPrompts.ID_NUMBER.first
val digits = normalizeDigits(cleanedValue(results[idKey]))
if (digits != null && isValidAadhaar(digits)) {
results["hasAadhar"] = "YES"
}
}
private fun computeDocType(results: Map<String, String>, handled: Boolean): String {
if (!handled) return "GENERAL"
return when {
@@ -454,3 +463,8 @@ private fun normalizeDigits(value: String?): String? {
val digits = value.filter { it.isDigit() }
return digits.ifBlank { null }
}
private fun isValidPin(value: String?): Boolean {
if (value.isNullOrBlank()) return false
return pinCodeRegex.matches(value)
}