From 9299d22c5be1b363cdc76ca41239915fe3a28af3 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sat, 31 Jan 2026 10:16:20 +0530 Subject: [PATCH] extractor: improve rules for extracting aadhar by verifying checksum --- .../component/DocumentExtractionService.kt | 16 +++++++++++++++- .../controller/DocumentPrompts.kt | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/component/DocumentExtractionService.kt b/src/main/kotlin/com/android/trisolarisserver/component/DocumentExtractionService.kt index 005a2ef..88b1647 100644 --- a/src/main/kotlin/com/android/trisolarisserver/component/DocumentExtractionService.kt +++ b/src/main/kotlin/com/android/trisolarisserver/component/DocumentExtractionService.kt @@ -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) { @@ -277,6 +278,14 @@ class DocumentExtractionService( } } + private fun markAadhaarIfValid(results: MutableMap) { + 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, 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) +} diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/DocumentPrompts.kt b/src/main/kotlin/com/android/trisolarisserver/controller/DocumentPrompts.kt index 2aecd03..cfc82e4 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/DocumentPrompts.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/DocumentPrompts.kt @@ -5,7 +5,7 @@ object DocumentPrompts { val DOB = "dob" to "DOB? Reply only date or NONE." val ID_NUMBER = "idNumber" to "ID NUMBER? Read extremely carefully. Reply only number or NONE." val ADDRESS = "address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE." - val PIN_CODE = "pinCode" to "POSTAL PIN CODE (6 digits). Do NOT return Aadhaar or 12-digit numbers. Reply only pin or NONE." + val PIN_CODE = "pinCode" to "CITY POSTAL PIN CODE. Reply only pin or NONE." val CITY = "city" to "CITY? Reply only city or NONE." val GENDER = "gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE." val NATIONALITY = "nationality" to "NATIONALITY? Reply only nationality or NONE."