handwritten ocr
This commit is contained in:
@@ -0,0 +1,864 @@
|
||||
"""
|
||||
Extraction schema definition for Marathi & English hospital forms.
|
||||
Tailored for Deenanath Mangeshkar Hospital & Research Centre Patient Registration Forms:
|
||||
1. English Form: 'DEENANATH MANGESHKAR HOSPITAL & RESEARCH CENTRE / PATIENT REGISTRATION FORM'
|
||||
2. Marathi Form: 'दीनानाथ मंगेशकर रुग्णालय आणि संशोधन केंद्र / रुग्ण नावनोंदणी अर्ज'
|
||||
|
||||
Incorporates comprehensive alphabet grounding (Marathi Devanagari + English Latin)
|
||||
and multi-tier anti-hallucination safeguards to eliminate synthetic/invented data on unfilled fields.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import re
|
||||
from text_repair_engine import TextRepairEngine
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
# Alphabet & Character Grounding Sets (मराठी वर्णमाला व इंग्रजी मुळाक्षरे)
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
MARATHI_VOWELS = "अ आ इ ई उ ऊ ऋ ऌ ए ऐ ओ औ अं अः ॲ ऑ"
|
||||
MARATHI_CONSONANTS = (
|
||||
"क ख ग घ ङ "
|
||||
"च छ ज झ ञ "
|
||||
"ट ठ ड ढ ण "
|
||||
"त थ द ध न "
|
||||
"प फ ब भ म "
|
||||
"य र ल व श ष स ह ळ क्ष ज्ञ"
|
||||
)
|
||||
MARATHI_MATRAS = "ा ि ी ु ू ृ ॄ े ै ो ौ ं ः ् ॅ ॉ ़"
|
||||
MARATHI_DIGITS_MAP = {
|
||||
"०": "0", "१": "1", "२": "2", "३": "3", "४": "4",
|
||||
"५": "5", "६": "6", "७": "7", "८": "8", "९": "9"
|
||||
}
|
||||
|
||||
ENGLISH_UPPERCASE = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
|
||||
ENGLISH_LOWERCASE = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
|
||||
ENGLISH_DIGITS = "0 1 2 3 4 5 6 7 8 9"
|
||||
|
||||
# Known printed form labels to prevent label-to-value hallucination
|
||||
PRINTED_LABELS_BLACKLIST = {
|
||||
# English form labels
|
||||
"last name / surname", "last name", "surname", "first name", "middle name",
|
||||
"date of birth (dd-mm-yyyy)", "date of birth", "dob", "approximate age in years",
|
||||
"approximate age", "age in years", "age",
|
||||
"flat / room / block no.", "flat / room / block no", "flat/room/block no.",
|
||||
"premises / building / village", "premises / building", "nearby landmark",
|
||||
"road / lane / post office", "road / lane", "area / locality / taluka",
|
||||
"town / city / district", "town / city", "city / district",
|
||||
"state / union territory", "state", "country name", "country",
|
||||
"pincode / zip code", "pincode", "zip code",
|
||||
"telephone no. with area / std code", "telephone no.", "mobile number",
|
||||
"alternate mobile number", "email id", "email",
|
||||
"aadhaar number", "aadhaar", "permanent account number (pan)", "pan",
|
||||
"source of income", "monthly income", "who will pay bills?", "who will pay bills",
|
||||
"name of the company", "company name", "consultant's name", "consultant name",
|
||||
"remark", "remarks", "name of the representative", "representative name",
|
||||
"representative's relation to patient", "representative's relation",
|
||||
"audited by", "entered by", "date", "mrd no.", "mrd no", "registration form",
|
||||
"signature", "patient", "representative", "relation to patient",
|
||||
"name & age of patient (full expanded name as appearing in proof of identity)",
|
||||
"local address (in pune)", "permanent address", "contact numbers, email id, aadhaar and pan",
|
||||
|
||||
# Marathi form labels
|
||||
"आडनाव", "पहिले नाव", "वडिलांचे वा पतीचे वा मधले नाव", "वडिलांचे नाव",
|
||||
"जन्मतारीख (dd-mm-yyyy)", "जन्मतारीख", "किंवा अंदाजे वय वर्षे", "अंदाजे वय वर्षे", "वय वर्षे", "वय",
|
||||
"स्थानिक पत्ता (पुण्यातील)", "स्थानिक पत्ता", "कायमचा पत्ता",
|
||||
"फ्लॅट / खोली / गट क्र.", "फ्लॅट / खोली / गट क्र", "फ्लॅट/खोली/गट क्र.",
|
||||
"परिसर / इमारत / गाव", "परिसर / इमारत", "घराजवळची खूण",
|
||||
"रस्ता / आळी / पोस्ट", "रस्ता / आळी", "विभाग / तालुका", "शहर / जिल्हा",
|
||||
"राज्य / केंद्रशासित प्रदेश", "पिनकोड / झिपकोड", "पिनकोड", "झिपकोड", "देश",
|
||||
"एसटीडी कोडसह दूरध्वनी क्रमांक", "दूरध्वनी क्रमांक", "दूरध्वनी",
|
||||
"भ्रमणध्वनी (मोबाईल) क्रमांक", "भ्रमणध्वनी", "मोबाईल क्रमांक", "मोबाईल",
|
||||
"पर्यायी भ्रमणध्वनी (मोबाईल) क्रमांक", "पर्यायी भ्रमणध्वनी",
|
||||
"ईमेल", "ईमेल आयडी", "आधार क्रमांक", "आधार", "पॅन :", "पॅन क्रमांक", "पॅन",
|
||||
"उत्पन्नाचा स्रोत निवडा", "उत्पन्नाचा स्रोत", "मासिक उत्पन्न - ₹", "मासिक उत्पन्न",
|
||||
"शुल्क कोण भरणार आहे? निवडा", "शुल्क कोण भरणार आहे?", "शुल्क कोण भरणार",
|
||||
"कंपनीचे नाव", "डॉक्टरांचे नाव", "शेरा",
|
||||
"स्वाक्षरी", "रुग्ण", "प्रतिनिधी", "प्रतिनिधीचे नाव", "प्रतिनिधीचे रुग्णाशी असलेले नाते",
|
||||
"तपासणीसाचे नाव", "नोंद घेणाऱ्याचे नाव", "दिनांक", "एमआरडी क्र.", "एमआरडी क्र"
|
||||
}
|
||||
|
||||
GENERIC_DUMMY_VALUES = {
|
||||
"null", "none", "nil", "n/a", "na", "undefined", "-", "—", "unknown",
|
||||
"john doe", "jane doe", "test patient", "sample", "xyz", "abc", "lorem ipsum"
|
||||
}
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
# Doc-AI Extract Schema Definition
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
EXTRACTION_SCHEMA = {
|
||||
"type": "object",
|
||||
"description": (
|
||||
"Hospital patient registration form extraction with dual-script grounding (Marathi Devanagari & English Latin) "
|
||||
"and strict zero-hallucination constraints for Deenanath Mangeshkar Hospital & Research Centre registration forms."
|
||||
),
|
||||
"properties": {
|
||||
"anti_hallucination_character_grounding": {
|
||||
"type": "string",
|
||||
"description": (
|
||||
"STRICT DUAL-SCRIPT GROUNDING & ANTI-HALLUCINATION PROTOCOL: "
|
||||
"1. SCRIPT CONSTRAINTS: "
|
||||
" - Marathi Devanagari Letters: स्वर [अ, आ, इ, ई, उ, ऊ, ऋ, ऌ, ए, ऐ, ओ, औ, अं, अः, ॲ, ऑ], "
|
||||
" व्यंजने [क, ख, ग, घ, ङ, च, छ, ज, झ, ञ, ट, ठ, ड, ढ, ण, त, थ, द, ध, न, प, फ, ब, भ, म, य, र, ल, व, श, ष, स, ह, ळ, क्ष, ज्ञ], "
|
||||
" मात्रा [ा, ि, ी, ु, ू, ृ, ॄ, े, ै, ो, ौ, ं, ः, ्, ॅ, ॉ, ़], "
|
||||
" अंक [०=0, १=1, २=2, ३=3, ४=4, ५=5, ६=6, ७=7, ८=8, ९=9]. "
|
||||
" - English Latin Letters: Uppercase [A-Z], Lowercase [a-z], Digits [0-9]. "
|
||||
"2. BLANK BOX & UNFILLED FIELD MANDATE: "
|
||||
" If any character box, dotted line, or text field has NO visible handwritten ink or typed entry, you MUST return null. "
|
||||
" DO NOT guess, fabricate, autocomplete, or invent any patient names, birth dates, phone numbers, or addresses. "
|
||||
"3. BLANK FORM TEMPLATE RULE: "
|
||||
" If the uploaded image is a blank template with no handwritten or patient-entered data, ALL patient details MUST be null. "
|
||||
"4. LABEL NON-DUPLICATION RULE: "
|
||||
" Never output printed prompt labels (e.g. 'Last Name / Surname', 'Flat / Room / Block No.', 'आडनाव') as patient data. "
|
||||
"5. NUMERIC RIGOR: "
|
||||
" Never confuse Marathi ४ with 9 or 5; never confuse Marathi ३ with 9 or 6; never confuse Marathi ५ with 4 or 7. "
|
||||
"6. CHECKBOX INTEGRITY: "
|
||||
" Only extract a checkbox choice if an explicit checkmark [✓] or [x] is visibly drawn. If unchecked, return null. "
|
||||
"7. ENGLISH SPELLINGS & PATIENT MISTAKE REPAIR MANDATE: "
|
||||
" - Convert to English Spellings: Even if the form is filled in Marathi Devanagari script, extract and provide all patient details, names, addresses, and relations in proper ENGLISH spellings (e.g. 'शिंदे' -> 'SHINDE', 'राम' -> 'RAM', 'पुणे' -> 'Pune', 'एरंडवणे' -> 'Erandwane', 'पुरुष' -> 'Male', 'आधार कार्ड' -> 'Aadhaar Card'). "
|
||||
" - Repair Handwriting Slips: If the patient made spelling errors, omitted characters, phonetic slips, or format mistakes in their handwriting (e.g. 'एरंडवना' -> 'Erandwane', 'शिदे' -> 'SHINDE', incomplete date '5/6/80' -> '05/06/1980'), intelligently REPAIR and correct it into standard, clean, well-spelled English. "
|
||||
" - Preserve raw handwritten text exactly in raw_transcription."
|
||||
)
|
||||
},
|
||||
"form_language": {
|
||||
"type": "string",
|
||||
"description": "Detected primary printed language of this form: 'en' for English ('PATIENT REGISTRATION FORM') or 'mr' for Marathi ('रुग्ण नावनोंदणी अर्ज')."
|
||||
},
|
||||
"document_type": {
|
||||
"type": "string",
|
||||
"description": "Type of document: 'hospital_registration_form', 'medical_note', or 'prescription'."
|
||||
},
|
||||
"hospital_name": {
|
||||
"type": "string",
|
||||
"description": "Hospital name printed at the top (e.g., 'DEENANATH MANGESHKAR HOSPITAL & RESEARCH CENTRE' or 'दीनानाथ मंगेशकर रुग्णालय आणि संशोधन केंद्र')."
|
||||
},
|
||||
"mrd_number": {
|
||||
"type": "string",
|
||||
"description": "MRD No. / एमआरडी क्र. printed or written in the top-right audit header box. If blank in the top box, return null. Do not hallucinate."
|
||||
},
|
||||
"barcode_number": {
|
||||
"type": "string",
|
||||
"description": "Registration barcode number printed at bottom-left under 'Registration Form' barcode (e.g., 'C00000039')."
|
||||
},
|
||||
"visit_date": {
|
||||
"type": "string",
|
||||
"description": "Date / दिनांक as written in the top audit header. Read exact digits only. Return null if blank."
|
||||
},
|
||||
"examiner_name": {
|
||||
"type": "string",
|
||||
"description": "Audited by / तपासणीसाचे नाव as written in top header box. Return null if blank."
|
||||
},
|
||||
"registrar_name": {
|
||||
"type": "string",
|
||||
"description": "Entered by / नोंद घेणाऱ्याचे नाव as written in top header box. Return null if blank."
|
||||
},
|
||||
"id_proof_type": {
|
||||
"type": "string",
|
||||
"description": "Selected ID proof checkbox: 'Aadhaar Card' (आधार कार्ड), 'Pan Card' (पॅन कार्ड), 'Driving License' (चालक परवाना), 'Election Card' (मतदार ओळखपत्र), 'Passport' (पासपोर्ट), 'Birth Certificate' (जन्म प्रमाणपत्र). Only extract if marked."
|
||||
},
|
||||
"gender": {
|
||||
"type": "string",
|
||||
"description": "Selected gender: 'Male'/'पुरुष', 'Female'/'स्त्री', 'Transgender'/'तृतीयपंथी'. Only extract if marked."
|
||||
},
|
||||
"salutation": {
|
||||
"type": "string",
|
||||
"description": "Selected title/salutation: Mr., Mrs., Mast., Miss., Smt., Dr., Mx, B/o, Fetus of. Only extract if marked."
|
||||
},
|
||||
"surname": {
|
||||
"type": "string",
|
||||
"description": "Last Name / Surname / आडनाव as handwritten inside the individual character boxes. Transcribe visible characters only (English A-Z or Marathi क-ज्ञ). Return null if boxes are blank."
|
||||
},
|
||||
"first_name": {
|
||||
"type": "string",
|
||||
"description": "First Name / पहिले नाव as handwritten inside the individual character boxes. Transcribe visible characters only (English A-Z or Marathi क-ज्ञ). Return null if boxes are blank."
|
||||
},
|
||||
"middle_name": {
|
||||
"type": "string",
|
||||
"description": "Middle Name / वडिलांचे वा पतीचे वा मधले नाव as handwritten inside the individual character boxes. Return null if blank."
|
||||
},
|
||||
"patient_name": {
|
||||
"type": "string",
|
||||
"description": "Full expanded patient name as written. If written separately in boxes, combine First Name + Middle Name + Surname. Return null if blank."
|
||||
},
|
||||
"dob": {
|
||||
"type": "string",
|
||||
"description": "Date of Birth / जन्मतारीख (dd-mm-yyyy) as handwritten in the boxes. Transcribe exact digits only. Return null if blank."
|
||||
},
|
||||
"age": {
|
||||
"type": "string",
|
||||
"description": "Approximate Age in Years / अंदाजे वय वर्षे as handwritten on the form line or box. Read exact digits only (e.g., '46' or '४६'). Return null if blank."
|
||||
},
|
||||
"local_address": {
|
||||
"type": "string",
|
||||
"description": "Local Address (in Pune) / स्थानिक पत्ता (पुण्यातील) including flat/room no, premises/building, landmark, road/lane, area/taluka, and pincode. Return null if blank."
|
||||
},
|
||||
"local_flat_room": {
|
||||
"type": "string",
|
||||
"description": "Local Flat / Room / Block No. (फ्लॅट / खोली / गट क्र.). Return null if blank."
|
||||
},
|
||||
"local_premises": {
|
||||
"type": "string",
|
||||
"description": "Local Premises / Building / Village (परिसर / इमारत / गाव). Return null if blank."
|
||||
},
|
||||
"local_landmark": {
|
||||
"type": "string",
|
||||
"description": "Local Nearby Landmark (घराजवळची खूण). Return null if blank."
|
||||
},
|
||||
"local_road": {
|
||||
"type": "string",
|
||||
"description": "Local Road / Lane / Post Office (रस्ता / आळी / पोस्ट). Return null if blank."
|
||||
},
|
||||
"local_taluka": {
|
||||
"type": "string",
|
||||
"description": "Local Area / Locality / Taluka (विभाग / तालुका). Return null if blank."
|
||||
},
|
||||
"local_pincode": {
|
||||
"type": "string",
|
||||
"description": "Local Pincode / Zip Code (पिनकोड) 6 digits as handwritten in the boxes. Return null if blank."
|
||||
},
|
||||
"permanent_address": {
|
||||
"type": "string",
|
||||
"description": "Permanent Address / कायमचा पत्ता including flat/room no, premises/building, landmark, road/lane, area/taluka, city/district, state, country, and pincode. Return null if blank."
|
||||
},
|
||||
"perm_flat_room": {
|
||||
"type": "string",
|
||||
"description": "Permanent Flat / Room / Block No. (फ्लॅट / खोली / गट क्र.). Return null if blank."
|
||||
},
|
||||
"perm_premises": {
|
||||
"type": "string",
|
||||
"description": "Permanent Premises / Building / Village (परिसर / इमारत / गाव). Return null if blank."
|
||||
},
|
||||
"perm_landmark": {
|
||||
"type": "string",
|
||||
"description": "Permanent Nearby Landmark (घराजवळची खूण). Return null if blank."
|
||||
},
|
||||
"perm_road": {
|
||||
"type": "string",
|
||||
"description": "Permanent Road / Lane / Post Office (रस्ता / आळी / पोस्ट). Return null if blank."
|
||||
},
|
||||
"perm_taluka": {
|
||||
"type": "string",
|
||||
"description": "Permanent Area / Locality / Taluka (विभाग / तालुका). Return null if blank."
|
||||
},
|
||||
"city_district": {
|
||||
"type": "string",
|
||||
"description": "Town / City / District / शहर / जिल्हा. Return null if blank."
|
||||
},
|
||||
"perm_state": {
|
||||
"type": "string",
|
||||
"description": "State / Union Territory / राज्य / केंद्रशासित प्रदेश. Return null if blank."
|
||||
},
|
||||
"perm_country": {
|
||||
"type": "string",
|
||||
"description": "Country Name / देश. Return null if blank."
|
||||
},
|
||||
"nationality": {
|
||||
"type": "string",
|
||||
"description": "Nationality / राष्ट्रीयत्व: 'Indian'/'भारतीय' or specified other. Return null if blank."
|
||||
},
|
||||
"pincode": {
|
||||
"type": "string",
|
||||
"description": "Permanent Pincode / Zip Code (पिनकोड/झिपकोड) 6 digits as handwritten in boxes. Return null if blank."
|
||||
},
|
||||
"telephone": {
|
||||
"type": "string",
|
||||
"description": "Telephone No. with Area / STD Code / एसटीडी कोडसह दूरध्वनी क्रमांक. Return null if blank."
|
||||
},
|
||||
"mobile_number": {
|
||||
"type": "string",
|
||||
"description": "Mobile Number / भ्रमणध्वनी (मोबाईल) क्रमांक (10 digits as written in boxes). Read exact digits only. Return null if blank."
|
||||
},
|
||||
"alternate_mobile": {
|
||||
"type": "string",
|
||||
"description": "Alternate Mobile Number / पर्यायी भ्रमणध्वनी (मोबाईल) क्रमांक (10 digits as written in boxes). Return null if blank."
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"description": "Email ID / ईमेल as written in boxes in English characters. Return null if blank."
|
||||
},
|
||||
"aadhaar_number": {
|
||||
"type": "string",
|
||||
"description": "AADHAAR Number / आधार क्रमांक (12 digits as written in boxes). Read exact digits only. Return null if blank."
|
||||
},
|
||||
"pan_number": {
|
||||
"type": "string",
|
||||
"description": "Permanent Account Number (PAN) / पॅन क्रमांक (10 alphanumeric characters as written in boxes). Return null if blank."
|
||||
},
|
||||
"income_source": {
|
||||
"type": "string",
|
||||
"description": "Selected Source of Income / उत्पन्नाचा स्रोत: 'Salary'/'पगार', 'Other Sources'/'अन्य स्रोत', 'Business / Profession'/'उद्योग वा व्यवसाय', 'No Income'/'उत्पन्न नाही'. Return null if not marked."
|
||||
},
|
||||
"monthly_income": {
|
||||
"type": "string",
|
||||
"description": "Monthly Income / मासिक उत्पन्न ₹ as written. Return null if blank."
|
||||
},
|
||||
"bill_payer": {
|
||||
"type": "string",
|
||||
"description": "Who will pay bills? / शुल्क कोण भरणार आहे?: 'Self'/'स्वतः', 'Company'/'कंपनी'. Return null if not marked."
|
||||
},
|
||||
"company_name": {
|
||||
"type": "string",
|
||||
"description": "Name of the Company / कंपनीचे नाव if bills paid by company. Return null if blank."
|
||||
},
|
||||
"doctor_name": {
|
||||
"type": "string",
|
||||
"description": "Consultant's Name / डॉक्टरांचे नाव as written on form. Return null if blank."
|
||||
},
|
||||
"remarks": {
|
||||
"type": "string",
|
||||
"description": "Remark / शेरा as handwritten on form. Return null if blank."
|
||||
},
|
||||
"signatory": {
|
||||
"type": "string",
|
||||
"description": "Signature / स्वाक्षरी: 'Patient'/'रुग्ण' or 'Representative'/'प्रतिनिधी'. Return null if not marked."
|
||||
},
|
||||
"representative_name": {
|
||||
"type": "string",
|
||||
"description": "Name of the Representative / प्रतिनिधीचे नाव if signed by representative. Return null if blank."
|
||||
},
|
||||
"representative_relation": {
|
||||
"type": "string",
|
||||
"description": "Representative's Relation to Patient / प्रतिनिधीचे रुग्णाशी असलेले नाते. Return null if blank."
|
||||
},
|
||||
"symptoms": {
|
||||
"type": "string",
|
||||
"description": "Patient symptoms or complaints if written in clinical notes area. Return null if blank."
|
||||
},
|
||||
"medical_history": {
|
||||
"type": "string",
|
||||
"description": "Medical history or past illnesses if written. Return null if blank."
|
||||
},
|
||||
"diagnosis": {
|
||||
"type": "string",
|
||||
"description": "Doctor's diagnosis if written. Return null if blank."
|
||||
},
|
||||
"medicines": {
|
||||
"type": "array",
|
||||
"description": "Prescribed medicines and dosages if present on document.",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string", "description": "Medicine name"},
|
||||
"dosage": {"type": "string", "description": "Dosage frequency / quantity"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"additional_notes": {
|
||||
"type": "string",
|
||||
"description": "Any additional handwritten notes found anywhere on document. Return null if blank."
|
||||
},
|
||||
"raw_transcription": {
|
||||
"type": "string",
|
||||
"description": (
|
||||
"Complete readable text transcribed verbatim from top to bottom, preserving original line breaks. "
|
||||
"For English forms, transcribe English Latin letters. For Marathi forms, transcribe Marathi Devanagari script. "
|
||||
"DO NOT hallucinate or insert words not visible on document. Mark unclear words with [illegible] or [अस्पष्ट]."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
# Standard Structured Response Template
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
EMPTY_RESPONSE_TEMPLATE = {
|
||||
"document_type": "hospital_registration_form",
|
||||
"form_language": "mr",
|
||||
"hospital_details": {
|
||||
"hospital_name": None,
|
||||
"mrd_number": None,
|
||||
"barcode_number": None,
|
||||
"visit_date": None,
|
||||
"examiner_name": None,
|
||||
"registrar_name": None,
|
||||
"department": None,
|
||||
"doctor_name": None,
|
||||
"remarks": None
|
||||
},
|
||||
"patient_details": {
|
||||
"patient_name": None,
|
||||
"surname": None,
|
||||
"first_name": None,
|
||||
"father_or_husband_name": None,
|
||||
"middle_name": None,
|
||||
"salutation": None,
|
||||
"gender": None,
|
||||
"dob": None,
|
||||
"age": None,
|
||||
"id_proof_type": None,
|
||||
"mobile_number": None,
|
||||
"alternate_mobile": None,
|
||||
"telephone": None,
|
||||
"email": None,
|
||||
"aadhaar_number": None,
|
||||
"pan_number": None,
|
||||
"address": None
|
||||
},
|
||||
"address_details": {
|
||||
"local_address": None,
|
||||
"local_flat_room": None,
|
||||
"local_premises": None,
|
||||
"local_landmark": None,
|
||||
"local_road": None,
|
||||
"local_taluka": None,
|
||||
"local_pincode": None,
|
||||
"permanent_address": None,
|
||||
"perm_flat_room": None,
|
||||
"perm_premises": None,
|
||||
"perm_landmark": None,
|
||||
"perm_road": None,
|
||||
"perm_taluka": None,
|
||||
"city_district": None,
|
||||
"perm_state": None,
|
||||
"perm_country": None,
|
||||
"nationality": None,
|
||||
"pincode": None
|
||||
},
|
||||
"billing_details": {
|
||||
"income_source": None,
|
||||
"monthly_income": None,
|
||||
"bill_payer": None,
|
||||
"company_name": None
|
||||
},
|
||||
"representative_details": {
|
||||
"signatory": None,
|
||||
"representative_name": None,
|
||||
"relationship": None
|
||||
},
|
||||
"medical_details": {
|
||||
"symptoms": None,
|
||||
"medical_history": None,
|
||||
"diagnosis": None,
|
||||
"medicines": [],
|
||||
"additional_notes": None
|
||||
},
|
||||
"raw_transcription": "",
|
||||
"repaired_fields": [],
|
||||
"unreadable_fields": [],
|
||||
"validation_warnings": []
|
||||
}
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
# Anti-Hallucination & Sanitization Helpers
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
def devanagari_to_arabic(text: str) -> str:
|
||||
"""Convert Marathi Devanagari digits (०-९) to standard digits (0-9)."""
|
||||
if not text or not isinstance(text, str):
|
||||
return text
|
||||
result = []
|
||||
for ch in text:
|
||||
result.append(MARATHI_DIGITS_MAP.get(ch, ch))
|
||||
return "".join(result)
|
||||
|
||||
|
||||
def sanitize_extracted_value(val: any) -> any:
|
||||
"""
|
||||
Sanitize an extracted string value against hallucinations:
|
||||
1. Nullify if value matches printed form labels (e.g. 'Last Name / Surname', 'आडनाव').
|
||||
2. Nullify if value is a generic placeholder ('null', 'n/a', 'John Doe').
|
||||
3. Strip whitespace.
|
||||
"""
|
||||
if val is None:
|
||||
return None
|
||||
if isinstance(val, (int, float)):
|
||||
return str(val)
|
||||
if not isinstance(val, str):
|
||||
return val
|
||||
|
||||
cleaned = val.strip()
|
||||
if not cleaned:
|
||||
return None
|
||||
|
||||
# Check case-insensitive blacklist
|
||||
lower_val = cleaned.lower()
|
||||
if lower_val in GENERIC_DUMMY_VALUES:
|
||||
return None
|
||||
|
||||
# Check against printed form labels
|
||||
cleaned_label_test = re.sub(r'[\:\.\,\-_/\(\)]+', ' ', lower_val).strip()
|
||||
if cleaned_label_test in PRINTED_LABELS_BLACKLIST or lower_val in PRINTED_LABELS_BLACKLIST:
|
||||
return None
|
||||
|
||||
return cleaned
|
||||
|
||||
|
||||
def reconcile_field_against_raw(
|
||||
field_name: str,
|
||||
extracted_val: str,
|
||||
raw_text: str,
|
||||
patterns: list,
|
||||
normalize_digits: bool = True
|
||||
):
|
||||
"""
|
||||
Check if raw handwritten transcription contains ground-truth text matching the field.
|
||||
If extracted value contradicts raw text, reconcile it and produce an anti-hallucination warning.
|
||||
"""
|
||||
if not raw_text or not isinstance(raw_text, str):
|
||||
return extracted_val, None
|
||||
|
||||
for pat in patterns:
|
||||
m = re.search(pat, raw_text, re.IGNORECASE)
|
||||
if m:
|
||||
ground_raw = m.group(1).strip()
|
||||
ground_normalized = devanagari_to_arabic(ground_raw) if normalize_digits else ground_raw
|
||||
|
||||
ext_normalized = devanagari_to_arabic(str(extracted_val)).strip() if (extracted_val and normalize_digits) else (str(extracted_val).strip() if extracted_val else "")
|
||||
|
||||
# If extracted value is missing but found in raw handwriting
|
||||
if not ext_normalized:
|
||||
warning = f"Anti-Hallucination Guard: Ground-truth value for '{field_name}' retrieved from raw handwriting: '{ground_raw}'."
|
||||
return ground_normalized, warning
|
||||
|
||||
# If extracted value contradicts raw handwriting
|
||||
if ext_normalized != ground_normalized:
|
||||
warning = (
|
||||
f"Anti-Hallucination Guard: Extracted value '{extracted_val}' for '{field_name}' contradicted "
|
||||
f"raw handwriting ('{ground_raw}'). Auto-corrected to '{ground_normalized}'."
|
||||
)
|
||||
return ground_normalized, warning
|
||||
|
||||
return extracted_val, None
|
||||
|
||||
|
||||
def detect_form_language(raw_text: str, extract_result: dict) -> str:
|
||||
"""
|
||||
Detect whether the form is English ('en') or Marathi ('mr') based on text features.
|
||||
"""
|
||||
# Check explicit result field first
|
||||
explicit_lang = (extract_result.get("form_language") or extract_result.get("language") or "").lower()
|
||||
if explicit_lang in ("en", "english", "en-in"):
|
||||
return "en"
|
||||
if explicit_lang in ("mr", "marathi", "mr-in"):
|
||||
return "mr"
|
||||
|
||||
text_to_check = (raw_text or "") + " " + (extract_result.get("hospital_name") or "")
|
||||
|
||||
# Look for unmistakable markers
|
||||
if "DEENANATH MANGESHKAR HOSPITAL" in text_to_check.upper() or "PATIENT REGISTRATION FORM" in text_to_check.upper():
|
||||
return "en"
|
||||
if "दीनानाथ मंगेशकर रुग्णालय" in text_to_check or "रुग्ण नावनोंदणी अर्ज" in text_to_check:
|
||||
return "mr"
|
||||
|
||||
# Count Devanagari characters vs Latin characters
|
||||
devanagari_count = len(re.findall(r'[\u0900-\u097F]', text_to_check))
|
||||
latin_count = len(re.findall(r'[a-zA-Z]', text_to_check))
|
||||
|
||||
if devanagari_count > latin_count:
|
||||
return "mr"
|
||||
elif latin_count > devanagari_count:
|
||||
return "en"
|
||||
return "mr"
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
# Response Builder
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
def build_structured_response(extract_result: dict) -> dict:
|
||||
"""
|
||||
Transform raw extract result into the structured nested response matching both forms.
|
||||
Applies multi-tier anti-hallucination checks, label sanitization, and digit normalization.
|
||||
"""
|
||||
response = copy.deepcopy(EMPTY_RESPONSE_TEMPLATE)
|
||||
|
||||
if not extract_result or not isinstance(extract_result, dict):
|
||||
response["validation_warnings"].append("No extraction result received from Vision API.")
|
||||
return response
|
||||
|
||||
# Flatten nested structures if passed an already-structured dictionary
|
||||
flat_data = {}
|
||||
for k, v in extract_result.items():
|
||||
if isinstance(v, dict) and k.endswith("_details"):
|
||||
for sub_k, sub_v in v.items():
|
||||
if sub_k not in flat_data or flat_data[sub_k] is None:
|
||||
flat_data[sub_k] = sub_v
|
||||
else:
|
||||
if k not in flat_data or flat_data[k] is None:
|
||||
flat_data[k] = v
|
||||
|
||||
response["document_type"] = sanitize_extracted_value(flat_data.get("document_type")) or "hospital_registration_form"
|
||||
|
||||
# Raw Transcription
|
||||
raw_text = flat_data.get("raw_transcription") or ""
|
||||
response["raw_transcription"] = raw_text
|
||||
|
||||
# Form Language
|
||||
lang = detect_form_language(raw_text, flat_data)
|
||||
response["form_language"] = lang
|
||||
|
||||
# Hospital & Registration Details
|
||||
h = response["hospital_details"]
|
||||
h["hospital_name"] = sanitize_extracted_value(flat_data.get("hospital_name"))
|
||||
# Barcode registration number at bottom left
|
||||
barcode = sanitize_extracted_value(flat_data.get("barcode_number")) or sanitize_extracted_value(flat_data.get("barcode"))
|
||||
h["barcode_number"] = barcode
|
||||
|
||||
# MRD Number: Top right box
|
||||
mrd = sanitize_extracted_value(flat_data.get("mrd_number")) or sanitize_extracted_value(flat_data.get("mrp_number"))
|
||||
# If top right MRD number is empty, check if barcode number is the registration ID
|
||||
if not mrd and barcode:
|
||||
mrd = barcode
|
||||
h["mrd_number"] = mrd
|
||||
|
||||
h["visit_date"] = sanitize_extracted_value(flat_data.get("visit_date"))
|
||||
h["examiner_name"] = sanitize_extracted_value(flat_data.get("examiner_name") or flat_data.get("audited_by"))
|
||||
h["registrar_name"] = sanitize_extracted_value(flat_data.get("registrar_name") or flat_data.get("entered_by"))
|
||||
h["department"] = sanitize_extracted_value(flat_data.get("department"))
|
||||
h["doctor_name"] = sanitize_extracted_value(flat_data.get("doctor_name") or flat_data.get("consultant_name"))
|
||||
h["remarks"] = sanitize_extracted_value(flat_data.get("remarks") or flat_data.get("remark"))
|
||||
|
||||
# Patient Identification
|
||||
p = response["patient_details"]
|
||||
p["surname"] = sanitize_extracted_value(flat_data.get("surname") or flat_data.get("last_name"))
|
||||
p["first_name"] = sanitize_extracted_value(flat_data.get("first_name"))
|
||||
p["middle_name"] = sanitize_extracted_value(flat_data.get("middle_name") or flat_data.get("father_or_husband_name"))
|
||||
p["father_or_husband_name"] = p["middle_name"]
|
||||
p["salutation"] = sanitize_extracted_value(flat_data.get("salutation") or flat_data.get("title"))
|
||||
p["gender"] = sanitize_extracted_value(flat_data.get("gender"))
|
||||
p["dob"] = sanitize_extracted_value(flat_data.get("dob") or flat_data.get("date_of_birth"))
|
||||
p["age"] = sanitize_extracted_value(flat_data.get("age") or flat_data.get("approximate_age"))
|
||||
p["id_proof_type"] = sanitize_extracted_value(flat_data.get("id_proof_type"))
|
||||
p["mobile_number"] = sanitize_extracted_value(flat_data.get("mobile_number"))
|
||||
p["alternate_mobile"] = sanitize_extracted_value(flat_data.get("alternate_mobile"))
|
||||
p["telephone"] = sanitize_extracted_value(flat_data.get("telephone"))
|
||||
p["email"] = sanitize_extracted_value(flat_data.get("email"))
|
||||
p["aadhaar_number"] = sanitize_extracted_value(flat_data.get("aadhaar_number"))
|
||||
p["pan_number"] = sanitize_extracted_value(flat_data.get("pan_number"))
|
||||
|
||||
# Compute Composite Patient Name
|
||||
patient_full = sanitize_extracted_value(flat_data.get("patient_name"))
|
||||
if not patient_full:
|
||||
parts = [p["salutation"], p["first_name"], p["middle_name"], p["surname"]]
|
||||
non_empty = [part.strip() for part in parts if part and isinstance(part, str) and part.strip()]
|
||||
if non_empty:
|
||||
patient_full = " ".join(non_empty)
|
||||
p["patient_name"] = patient_full
|
||||
|
||||
# Address Details
|
||||
a = response["address_details"]
|
||||
a["local_flat_room"] = sanitize_extracted_value(flat_data.get("local_flat_room") or flat_data.get("flat_room_no"))
|
||||
a["local_premises"] = sanitize_extracted_value(flat_data.get("local_premises") or flat_data.get("premises_building"))
|
||||
a["local_landmark"] = sanitize_extracted_value(flat_data.get("local_landmark") or flat_data.get("nearby_landmark"))
|
||||
a["local_road"] = sanitize_extracted_value(flat_data.get("local_road") or flat_data.get("road_lane"))
|
||||
a["local_taluka"] = sanitize_extracted_value(flat_data.get("local_taluka") or flat_data.get("area_locality_taluka"))
|
||||
a["local_pincode"] = sanitize_extracted_value(flat_data.get("local_pincode"))
|
||||
|
||||
# Local address composite or direct string
|
||||
loc_addr = sanitize_extracted_value(flat_data.get("local_address"))
|
||||
if not loc_addr:
|
||||
loc_parts = [a["local_flat_room"], a["local_premises"], a["local_landmark"], a["local_road"], a["local_taluka"], a["local_pincode"]]
|
||||
loc_non_empty = [part.strip() for part in loc_parts if part and isinstance(part, str) and part.strip()]
|
||||
if loc_non_empty:
|
||||
loc_addr = ", ".join(loc_non_empty)
|
||||
a["local_address"] = loc_addr
|
||||
|
||||
# Permanent address components
|
||||
a["perm_flat_room"] = sanitize_extracted_value(flat_data.get("perm_flat_room"))
|
||||
a["perm_premises"] = sanitize_extracted_value(flat_data.get("perm_premises"))
|
||||
a["perm_landmark"] = sanitize_extracted_value(flat_data.get("perm_landmark"))
|
||||
a["perm_road"] = sanitize_extracted_value(flat_data.get("perm_road"))
|
||||
a["perm_taluka"] = sanitize_extracted_value(flat_data.get("perm_taluka"))
|
||||
a["city_district"] = sanitize_extracted_value(flat_data.get("city_district") or flat_data.get("town_city_district"))
|
||||
a["perm_state"] = sanitize_extracted_value(flat_data.get("perm_state") or flat_data.get("state"))
|
||||
a["perm_country"] = sanitize_extracted_value(flat_data.get("perm_country") or flat_data.get("country"))
|
||||
a["nationality"] = sanitize_extracted_value(flat_data.get("nationality"))
|
||||
a["pincode"] = sanitize_extracted_value(flat_data.get("pincode"))
|
||||
|
||||
# Permanent address composite or direct string
|
||||
perm_addr = sanitize_extracted_value(flat_data.get("permanent_address"))
|
||||
if not perm_addr:
|
||||
perm_parts = [a["perm_flat_room"], a["perm_premises"], a["perm_landmark"], a["perm_road"], a["perm_taluka"], a["city_district"], a["perm_state"], a["pincode"], a["perm_country"]]
|
||||
perm_non_empty = [part.strip() for part in perm_parts if part and isinstance(part, str) and part.strip()]
|
||||
if perm_non_empty:
|
||||
perm_addr = ", ".join(perm_non_empty)
|
||||
a["permanent_address"] = perm_addr
|
||||
|
||||
# Backward compatibility address field on patient_details
|
||||
p["address"] = a["permanent_address"] or a["local_address"]
|
||||
|
||||
# Billing Details
|
||||
b = response["billing_details"]
|
||||
b["income_source"] = sanitize_extracted_value(flat_data.get("income_source"))
|
||||
b["monthly_income"] = sanitize_extracted_value(flat_data.get("monthly_income"))
|
||||
b["bill_payer"] = sanitize_extracted_value(flat_data.get("bill_payer"))
|
||||
b["company_name"] = sanitize_extracted_value(flat_data.get("company_name"))
|
||||
|
||||
# Representative Details
|
||||
r = response["representative_details"]
|
||||
r["signatory"] = sanitize_extracted_value(flat_data.get("signatory"))
|
||||
r["representative_name"] = sanitize_extracted_value(flat_data.get("representative_name"))
|
||||
r["relationship"] = sanitize_extracted_value(flat_data.get("representative_relation") or flat_data.get("relationship"))
|
||||
|
||||
# Medical Details
|
||||
m = response["medical_details"]
|
||||
m["symptoms"] = sanitize_extracted_value(flat_data.get("symptoms"))
|
||||
m["medical_history"] = sanitize_extracted_value(flat_data.get("medical_history"))
|
||||
m["diagnosis"] = sanitize_extracted_value(flat_data.get("diagnosis"))
|
||||
m["additional_notes"] = sanitize_extracted_value(flat_data.get("additional_notes"))
|
||||
raw_meds = flat_data.get("medicines", [])
|
||||
m["medicines"] = raw_meds if isinstance(raw_meds, list) else []
|
||||
|
||||
# ── Multi-Tier Anti-Hallucination Cross-Verification ──
|
||||
hallucination_warnings = []
|
||||
|
||||
if raw_text:
|
||||
# Age reconciliation (Devanagari or English)
|
||||
age_patterns = [
|
||||
r'(?:वय|अंदाजे\s*वय|Approximate\s*Age|Age)\s*[:\-–=]+\s*([०-९0-9]+)',
|
||||
r'(?:वय|Age)\s*[:\-–=]*\s*([०-९0-9]+)\s*(?:वर्षे?|Years?)'
|
||||
]
|
||||
p["age"], w_age = reconcile_field_against_raw("Age / वय", p["age"], raw_text, age_patterns)
|
||||
if w_age:
|
||||
hallucination_warnings.append(w_age)
|
||||
|
||||
# DOB reconciliation
|
||||
dob_patterns = [
|
||||
r'(?:जन्मतारीख|जन्म\s*तारीख|Date\s*of\s*Birth|DOB)\s*[:\-–=]+\s*([०-९0-9]{1,2}[\/\.\-][०-९0-9]{1,2}[\/\.\-][०-९0-9]{2,4})',
|
||||
]
|
||||
p["dob"], w_dob = reconcile_field_against_raw("Date of Birth / जन्मतारीख", p["dob"], raw_text, dob_patterns)
|
||||
if w_dob:
|
||||
hallucination_warnings.append(w_dob)
|
||||
|
||||
# PIN Code reconciliation
|
||||
pincode_patterns = [
|
||||
r'(?:पिनकोड|पिन\s*कोड|Pincode|Pin\s*Code|Zip\s*Code)\s*[:\-–=]+\s*([०-९0-9]{6})',
|
||||
r'\b([०-९0-9]{6})\b'
|
||||
]
|
||||
a["pincode"], w_pin = reconcile_field_against_raw("PIN Code / पिनकोड", a["pincode"], raw_text, pincode_patterns)
|
||||
if w_pin:
|
||||
hallucination_warnings.append(w_pin)
|
||||
|
||||
# MRD Number reconciliation
|
||||
mrd_patterns = [
|
||||
r'(?:एम\s*आर\s*डी\s*क्र\.|MRD\s*No\.?|Registration\s*No\.?)\s*[:\-–=]+\s*([A-Za-z0-9०-९\-_]+)'
|
||||
]
|
||||
h["mrd_number"], w_mrd = reconcile_field_against_raw("MRD No. / एमआरडी क्र.", h["mrd_number"], raw_text, mrd_patterns, normalize_digits=False)
|
||||
if w_mrd:
|
||||
hallucination_warnings.append(w_mrd)
|
||||
|
||||
# Mobile Number reconciliation
|
||||
mobile_patterns = [
|
||||
r'(?:मोबाईल\s*क्रमांक|भ्रमणध्वनी|Mobile\s*Number|Mobile)\s*[:\-–=]+\s*([०-९0-9]{10})'
|
||||
]
|
||||
p["mobile_number"], w_mob = reconcile_field_against_raw("Mobile Number / मोबाईल क्रमांक", p["mobile_number"], raw_text, mobile_patterns)
|
||||
if w_mob:
|
||||
hallucination_warnings.append(w_mob)
|
||||
|
||||
# ── Marathi to English Conversion & Handwriting Mistake Repair ──
|
||||
repairs_applied = []
|
||||
repair_sections = [
|
||||
("hospital_details", h),
|
||||
("patient_details", p),
|
||||
("address_details", a),
|
||||
("billing_details", b),
|
||||
("representative_details", r),
|
||||
("medical_details", m)
|
||||
]
|
||||
|
||||
for sec_name, sec_dict in repair_sections:
|
||||
for field_key, original_val in list(sec_dict.items()):
|
||||
if original_val is not None and not isinstance(original_val, (list, dict)):
|
||||
repaired_val, repair_note = TextRepairEngine.convert_and_repair(field_key, original_val)
|
||||
sec_dict[field_key] = repaired_val
|
||||
if repair_note and str(repaired_val) != str(original_val):
|
||||
repairs_applied.append({
|
||||
"section": sec_name,
|
||||
"field": field_key,
|
||||
"original": str(original_val),
|
||||
"repaired": str(repaired_val),
|
||||
"note": repair_note
|
||||
})
|
||||
|
||||
# Recompute Composite Patient Name with repaired English name parts
|
||||
if p["first_name"] or p["surname"]:
|
||||
name_parts = [p["salutation"], p["first_name"], p["middle_name"], p["surname"]]
|
||||
valid_parts = [part.strip() for part in name_parts if part and isinstance(part, str) and part.strip()]
|
||||
if valid_parts:
|
||||
p["patient_name"] = " ".join(valid_parts)
|
||||
|
||||
# Recompute Address string if address components were converted/repaired
|
||||
if a["local_flat_room"] or a["local_premises"] or a["local_road"]:
|
||||
loc_parts = [a["local_flat_room"], a["local_premises"], a["local_landmark"], a["local_road"], a["local_taluka"], a["local_pincode"]]
|
||||
loc_non_empty = [part.strip() for part in loc_parts if part and isinstance(part, str) and part.strip()]
|
||||
if loc_non_empty:
|
||||
a["local_address"] = ", ".join(loc_non_empty)
|
||||
|
||||
p["address"] = a["permanent_address"] or a["local_address"]
|
||||
response["repaired_fields"] = repairs_applied
|
||||
|
||||
if repairs_applied:
|
||||
for r_item in repairs_applied:
|
||||
hallucination_warnings.append(
|
||||
f"🔧 Auto-Repaired '{r_item['field']}': '{r_item['original']}' → '{r_item['repaired']}' ({r_item['note']})"
|
||||
)
|
||||
|
||||
# Calculate unreadable / unfilled fields
|
||||
unreadable = []
|
||||
tracked_fields = [
|
||||
("patient_name", p["patient_name"]),
|
||||
("first_name", p["first_name"]),
|
||||
("surname", p["surname"]),
|
||||
("age", p["age"]),
|
||||
("dob", p["dob"]),
|
||||
("gender", p["gender"]),
|
||||
("mobile_number", p["mobile_number"]),
|
||||
("local_address", a["local_address"]),
|
||||
("permanent_address", a["permanent_address"]),
|
||||
("mrd_number", h["mrd_number"]),
|
||||
("visit_date", h["visit_date"]),
|
||||
("aadhaar_number", p["aadhaar_number"]),
|
||||
("pan_number", p["pan_number"])
|
||||
]
|
||||
for name, val in tracked_fields:
|
||||
if val is None or (isinstance(val, str) and val.strip() == ""):
|
||||
unreadable.append(name)
|
||||
|
||||
response["unreadable_fields"] = sorted(unreadable)
|
||||
|
||||
# Blank Form Template Detection & Warnings
|
||||
warnings = []
|
||||
is_blank_form = False
|
||||
if not p["patient_name"] and not p["surname"] and not p["first_name"] and not p["mobile_number"] and not a["local_address"]:
|
||||
is_blank_form = True
|
||||
warnings.append("🛡️ Unfilled Form Template Detected: Character boxes and patient fields are blank (Zero Hallucination).")
|
||||
|
||||
if not response["raw_transcription"]:
|
||||
warnings.append("Raw transcription is empty — document may be blank or low resolution.")
|
||||
|
||||
warnings.extend(hallucination_warnings)
|
||||
response["validation_warnings"] = warnings
|
||||
|
||||
return response
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
# Digitise Prompt for Bilingual Forms
|
||||
# ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
DIGITISE_SYSTEM_PROMPT = """You are a precision document intelligence system specializing in handwritten and printed hospital registration forms in both Marathi (Devanagari script) and English (Latin script).
|
||||
|
||||
Supported Document Types:
|
||||
1. रुग्ण नावनोंदणी अर्ज (Marathi Patient Registration Form - Deenanath Mangeshkar Hospital & Research Centre)
|
||||
2. PATIENT REGISTRATION FORM (English Patient Registration Form - Deenanath Mangeshkar Hospital & Research Centre)
|
||||
|
||||
Grounding Alphabets:
|
||||
- Marathi Devanagari Vowels: अ, आ, इ, ई, उ, ऊ, ऋ, ऌ, ए, ऐ, ओ, औ, अं, अः, ॲ, ऑ
|
||||
- Marathi Devanagari Consonants: क, ख, ग, घ, ङ, च, छ, ज, झ, ञ, ट, ठ, ड, ढ, ण, त, थ, द, ध, न, प, फ, ब, भ, म, य, र, ल, व, श, ष, स, ह, ळ, क्ष, ज्ञ
|
||||
- Marathi Matras: ा, ि, ी, ु, ू, ृ, ॄ, े, ै, ो, ौ, ं, ः, ्, ॅ, ॉ, ़
|
||||
- Marathi Numerals: ०=0, १=1, २=2, ३=3, ४=4, ५=5, ६=6, ७=7, ८=8, ९=9
|
||||
- English Alphabet: Uppercase A-Z, Lowercase a-z, Digits 0-9
|
||||
|
||||
STRICT ANTI-HALLUCINATION RULES:
|
||||
1. Transcribe ONLY visible characters that actually appear on the document.
|
||||
2. If character boxes or dotted lines are blank, leave them blank. DO NOT guess, synthesize, or invent names, dates, or phone numbers.
|
||||
3. If an entire form template is blank and unfilled, transcribe only the printed hospital headers and labels. Never fabricate patient data.
|
||||
4. If a word or number is partially illegible, mark it as [unclear] or [अस्पष्ट].
|
||||
5. Carefully distinguish Devanagari numerals: ४=4 (NOT 9 or 5), ३=3 (NOT 9 or 6), ५=5 (NOT 4 or 7).
|
||||
6. Maintain top-to-bottom reading order.
|
||||
"""
|
||||
Reference in New Issue
Block a user