extractor: improve rules for extracting aadhar by verifying checksum
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user