From 3d1bf64790052fff62ba804acbbfb07a42a6941b Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sat, 31 Jan 2026 01:11:58 +0530 Subject: [PATCH] Add isYes helper for AI results --- .../controller/GuestDocuments.kt | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt b/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt index 6729452..5a8f44a 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt @@ -214,8 +214,7 @@ class GuestDocuments( val results = linkedMapOf() results["hasAadhar"] = llamaClient.ask(imageUrl, "CONTAINS AADHAAR? Answer YES or NO only.") results["hasUidai"] = llamaClient.ask(imageUrl, "CONTAINS UIDAI? Answer YES or NO only.") - val hasAadhar = results["hasAadhar"].orEmpty().contains("YES", true) || - results["hasUidai"].orEmpty().contains("YES", true) + val hasAadhar = isYes(results["hasAadhar"]) || isYes(results["hasUidai"]) if (hasAadhar) { val aadharQuestions = linkedMapOf( "hasAddress" to "ADDRESS PRESENT? Answer YES or NO only.", @@ -262,22 +261,22 @@ class GuestDocuments( } results["docType"] = when { - results["hasCourt"].orEmpty().contains("YES", ignoreCase = true) || - results["hasHighCourt"].orEmpty().contains("YES", ignoreCase = true) || - results["hasSupremeCourt"].orEmpty().contains("YES", ignoreCase = true) || - results["hasJudiciary"].orEmpty().contains("YES", ignoreCase = true) -> "COURT_ID" - results["hasPolice"].orEmpty().contains("YES", ignoreCase = true) -> "POLICE_ID" - results["hasPassport"].orEmpty().contains("YES", ignoreCase = true) -> "PASSPORT" - results["hasTransportDept"].orEmpty().contains("YES", ignoreCase = true) || - results["hasDrivingLicence"].orEmpty().contains("YES", ignoreCase = true) -> "TRANSPORT" - results["hasIncomeTaxDept"].orEmpty().contains("YES", ignoreCase = true) -> "PAN" - results["hasElectionCommission"].orEmpty().contains("YES", ignoreCase = true) -> "VOTER_ID" - results["hasAadhar"].orEmpty().contains("YES", ignoreCase = true) || - results["hasUidai"].orEmpty().contains("YES", ignoreCase = true) -> { - if (results["hasAddress"].orEmpty().contains("YES", ignoreCase = true)) "AADHAR_BACK" else "AADHAR_FRONT" + isYes(results["hasCourt"]) || + isYes(results["hasHighCourt"]) || + isYes(results["hasSupremeCourt"]) || + isYes(results["hasJudiciary"]) -> "COURT_ID" + isYes(results["hasPolice"]) -> "POLICE_ID" + isYes(results["hasPassport"]) -> "PASSPORT" + isYes(results["hasTransportDept"]) || + isYes(results["hasDrivingLicence"]) -> "TRANSPORT" + isYes(results["hasIncomeTaxDept"]) -> "PAN" + isYes(results["hasElectionCommission"]) -> "VOTER_ID" + isYes(results["hasAadhar"]) || + isYes(results["hasUidai"]) -> { + if (isYes(results["hasAddress"])) "AADHAR_BACK" else "AADHAR_FRONT" } results["vehicleNumber"].orEmpty().isNotBlank() && !results["vehicleNumber"]!!.contains("NONE", true) -> "VEHICLE" - results["isVehiclePhoto"].orEmpty().contains("YES", ignoreCase = true) -> "VEHICLE_PHOTO" + isYes(results["isVehiclePhoto"]) -> "VEHICLE_PHOTO" else -> "UNKNOWN" } @@ -354,3 +353,7 @@ private fun GuestDocument.toResponse(objectMapper: ObjectMapper): GuestDocumentR extractedAt = extractedAt?.toString() ) } + +private fun isYes(value: String?): Boolean { + return value.orEmpty().contains("YES", ignoreCase = true) +}