"""
Taxonomy mapping configuration for historical complaint import (2022).

Maps Excel classification names to ComplaintCategory UUIDs.
"""

import re


# Domain mappings (Level 1) - Maps Excel Domain → ComplaintCategory UUID
DOMAIN_MAPPING = {
    "Clinical complaints": "d7bb3c2d-9f80-4d8c-85dc-ca5ac139417a",  # CLINICAL / سريري
    "Clinical Care": "51d3e74b-7c7f-48aa-98ef-475f97a47d0d",  # الرعاية السريرية
    "Relationship complaints": "f8263c2e-a89b-4ab7-bccd-a1524d85524c",  # RELATIONSHIPS / علاقات
    "Relationships": "73f83d5f-81a1-4340-970c-46d2950e7c98",  # العلاقات
    "Management complaints": "a58cb0ee-4622-4996-99ad-e134b88687e6",  # MANAGEMENT / إداري
    "Management": "70f95ca0-436f-4a1f-9ea5-9de2625e70c9",  # الإدارة
}

# Category mappings (Level 2) - Maps Excel Category → ComplaintCategory UUID
CATEGORY_MAPPING = {
    "Quality": "416a4c10-5739-4e27-a62f-ea5f107f0e81",  # الجودة
    "1. Quality": "416a4c10-5739-4e27-a62f-ea5f107f0e81",  # الجودة
    "Safety": "29e47b23-a724-46da-b128-b7ceb7546da0",  # السلامة
    "2. Safety": "29e47b23-a724-46da-b128-b7ceb7546da0",  # السلامة
    "Institutional Issues": "ca1619c9-7df4-4c97-b216-7a8113917997",  # القضايا المؤسسية
    "3. Institutional issues": "ca1619c9-7df4-4c97-b216-7a8113917997",  # القضايا المؤسسية
    "Accessibility": "313679ed-9749-4e6c-9f92-9c9a4126f6bf",  # سهولة الوصول
    "4. Accessibility": "313679ed-9749-4e6c-9f92-9c9a4126f6bf",  # سهولة الوصول
    "Communication": "51b66802-59c8-42db-9f04-b7d468bc2408",  # التواصل
    "5. Communication": "51b66802-59c8-42db-9f04-b7d468bc2408",  # التواصل
    "Humanness / Caring": "7409fc81-8d66-4028-aa1b-8b3143c39b46",  # الإنسانية / الرعاية
    "6. Humanness / Caring": "7409fc81-8d66-4028-aa1b-8b3143c39b46",  # الإنسانية / الرعاية
    "Confidentiality": "6a2d6d89-fdcb-425a-97a0-f3e524d0090b",  # الخصوصية
    "Consent": "54f695ca-4050-4b23-a463-ce4b136db173",  # الموافقة
    "4. Finance and Billing": "7f87c9c4-68df-48e7-81a4-4bebd7376253",  # المالية والفواتير
    "5. Incorrect Information": "6e75d91a-5c1e-4f1b-a71b-ba90b7a2ba5b",  # معلومات غير صحيحة
    "6. Confidentiality": "6a2d6d89-fdcb-425a-97a0-f3e524d0090b",  # الخصوصية
}

# Sub-Category mappings (Level 3) - Maps Excel Sub-Category → ComplaintCategory UUID
SUBCATEGORY_MAPPING = {
    "Examination": "a173a340-9dee-4115-a901-b4555e546500",  # الفحص
    "1.1. Examination": "a173a340-9dee-4115-a901-b4555e546500",  # الفحص
    "Patient Journey": "23be662b-ae71-43c3-9a19-09388c903468",  # رحلة المريض
    "Patient journey": "23be662b-ae71-43c3-9a19-09388c903468",  # رحلة المريض
    "1.2.Patient journey": "23be662b-ae71-43c3-9a19-09388c903468",  # رحلة المريض
    "Quality of Care": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",  # جودة الرعاية
    "1.3.Quality of Care": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",  # جودة الرعاية
    "Treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",  # العلاج
    "1.4.Treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",  # العلاج
    "Diagnosis": "9335435e-98fb-48cd-b153-102ce4f5a39d",  # التشخيص
    "1.5.Diagnosis": "9335435e-98fb-48cd-b153-102ce4f5a39d",  # التشخيص
    "Medication & Vaccination": "287ba991-305b-4585-bd3a-1bf2c8b19397",  # الأدوية واللقاحات
    "Medication and Vaccination": "287ba991-305b-4585-bd3a-1bf2c8b19397",  # الأدوية واللقاحات
    "2.1.Medication & Vaccination": "287ba991-305b-4585-bd3a-1bf2c8b19397",  # الأدوية واللقاحات
    "Safety Incidents": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",  # حوادث السلامة
    "2.2.Safety Incidents": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",  # حوادث السلامة
    "Skills and Conduct": "cb7032f8-cb95-4d2c-81d6-d1f0e4119800",  # المهارات والسلوك
    "2.3.Skills and Conduct": "cb7032f8-cb95-4d2c-81d6-d1f0e4119800",  # المهارات والسلوك
    "Administrative Policies": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",  # السياسات الإدارية
    "3.1.Administrative Policies and Procedures": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",  # السياسات الإدارية
    "Environment": "7108f73c-300e-4212-939f-64264721888c",  # البيئة
    "3.2.Environment": "7108f73c-300e-4212-939f-64264721888c",  # البيئة
    "Safety & Security": "86f5fdac-df2a-4d4a-a97a-47812e14489a",  # الأمن والسلامة
    "3.3.Safety & Security": "86f5fdac-df2a-4d4a-a97a-47812e14489a",  # الأمن والسلامة
    "Finance and Billing": "7f87c9c4-68df-48e7-81a4-4bebd7376253",  # المالية والفواتير
    "3.4.Finance and Billing": "7f87c9c4-68df-48e7-81a4-4bebd7376253",  # المالية والفواتير
    "Resources": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",  # الموارد
    "3.6.Resources": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",  # الموارد
    "Access": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",  # الوصول
    "4.1.Access": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",  # الوصول
    "Delays": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",  # التأخير
    "4.3.Delays": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",  # التأخير
    "Patient-staff communication": "b1ef5b10-dc5a-49fc-9fc6-277ca4d41609",  # التواصل بين المريض والموظفين
    "5.1.Patient-staff Communication": "b1ef5b10-dc5a-49fc-9fc6-277ca4d41609",  # التواصل بين المريض والموظفين
    "Emotional Support": "51087d24-2803-448e-a9dc-aba310fcc15b",  # الدعم العاطفي
    "6.1.Emotional Support": "51087d24-2803-448e-a9dc-aba310fcc15b",  # الدعم العاطفي
    "Assault and Harassment": "5721210d-0294-4356-ab7d-eebe4e5ab9d7",  # الاعتداء والمضايقة
    "6.2.Assault  and Harassment": "5721210d-0294-4356-ab7d-eebe4e5ab9d7",  # الاعتداء والمضايقة
    "6.2.Assault and Harassment": "5721210d-0294-4356-ab7d-eebe4e5ab9d7",  # الاعتداء والمضايقة
    "Consent Process": "e6ff3ace-a4e6-4d44-a7f4-178b846b632c",  # إجراءات الموافقة
    "Privacy": "68d32c04-6c99-40b5-949d-10e78becbb99",  # خصوصية المعلومات
    "6.3.Confidentiality": "68d32c04-6c99-40b5-949d-10e78becbb99",  # خصوصية المعلومات
    "3.5.Staffing": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",  # الموارد
    "4.2.Patient Disposition (final plan)": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",  # التأخير
    "4.4.Referrals": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",  # الوصول
    "3.7.Medical records": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",  # السياسات الإدارية
    "6.4.Consent": "e6ff3ace-a4e6-4d44-a7f4-178b846b632c",  # إجراءات الموافقة
    "5.2.Incorrect Information": "6e75d91a-5c1e-4f1b-a71b-ba90b7a2ba5b",  # معلومات غير صحيحة
}

# Classification mappings (Level 4) - Maps Excel Classification → ComplaintCategory UUID
CLASSIFICATION_MAPPING = {
    "Patient flow issues": "8488fbf4-610e-4754-b2bb-096a67c4305c",
    "1.2.2.Patient flow issues": "8488fbf4-610e-4754-b2bb-096a67c4305c",
    "Substandard clinical/nursing care": "884bace8-9402-456c-9ced-1f140e9938c0",
    "1.3.1.Substandard clinical/nursing care": "884bace8-9402-456c-9ced-1f140e9938c0",
    "Errors in diagnosis": "3ab515e6-0504-48b6-8c83-dab0475ac331",
    "1.5.1.Errors in diagnosis": "3ab515e6-0504-48b6-8c83-dab0475ac331",
    "Dispensing errors": "23af36a6-3050-4fe4-bb30-d5d61abccb7a",
    "2.1.2.Dispensing errors": "23af36a6-3050-4fe4-bb30-d5d61abccb7a",
    # 'Calculate Additional amount': 'NOT-IN-SYSTEM',  # Not found in current taxonomy,
    # '3.4.3.Calculate Additional amount': 'NOT-IN-SYSTEM',  # Not found in current taxonomy,
    "Unnecessary health services": "24433748-9854-4cfe-9e32-65f4fb70c5c1",
    "3.4.6.Unnecessary health services": "24433748-9854-4cfe-9e32-65f4fb70c5c1",
    "Examination delay": "af9f4297-7094-416b-a9b2-b5d1b3f212c3",  # Examination delay in emergency,
    "4.3.3.Examination delay": "af9f4297-7094-416b-a9b2-b5d1b3f212c3",  # Examination delay in emergency,
    "Miscommunication with Patient": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "5.1.1.Miscommunication with Patient": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "Inappropriate/aggressive behavior": "9767593f-9be0-481f-8520-d5e855de3d8b",
    "6.2.1.Inappropriate/aggressive behavior": "9767593f-9be0-481f-8520-d5e855de3d8b",
    "Inadequate emotional support": "51087d24-2803-448e-a9dc-aba310fcc15b",
    "6.1.1.Inadequate emotional support": "51087d24-2803-448e-a9dc-aba310fcc15b",
    "Poor provider-patient communication": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "5.1.2.Poor provider-patient communication": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "Neglect": "51087d24-2803-448e-a9dc-aba310fcc15b",
    "6.1.2.Neglect": "51087d24-2803-448e-a9dc-aba310fcc15b",
    "1.2.Neglect": "23be662b-ae71-43c3-9a19-09388c903468",
    "Miscoordination": "23be662b-ae71-43c3-9a19-09388c903468",
    "1.2.1.Miscoordination": "23be662b-ae71-43c3-9a19-09388c903468",
    "Lack of follow up": "23be662b-ae71-43c3-9a19-09388c903468",
    "1.2.3.Lack of follow up": "23be662b-ae71-43c3-9a19-09388c903468",
    "Rough treatment": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",
    "1.3.3.Rough treatment": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",
    "Insensitive to patient needs": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",
    "1.3.4.Insensitive to patient needs": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",
    "Inadequate/incomplete assessment": "884bace8-9402-456c-9ced-1f140e9938c0",
    "1.1.2. Inadequate/incomplete assessment": "884bace8-9402-456c-9ced-1f140e9938c0",
    "2. Inadequate/incomplete assessment": "884bace8-9402-456c-9ced-1f140e9938c0",
    "Examination not performed": "a173a340-9dee-4115-a901-b4555e546500",
    "1.1.1. Examination not performed": "a173a340-9dee-4115-a901-b4555e546500",
    "Lab tests not performed": "a173a340-9dee-4115-a901-b4555e546500",
    "1.1.4. Lab tests not performed": "a173a340-9dee-4115-a901-b4555e546500",
    "Diagnostic Imaging not performed": "a173a340-9dee-4115-a901-b4555e546500",
    "1.1.5. Diagnostic Imaging not performed": "a173a340-9dee-4115-a901-b4555e546500",
    "Loss of a patient sample": "a173a340-9dee-4115-a901-b4555e546500",
    "1.1.6.Loss of a patient sample": "a173a340-9dee-4115-a901-b4555e546500",
    "Not having enough knowledge regarding the patient condition": "a173a340-9dee-4115-a901-b4555e546500",
    "1.1.3. Not having enough knowledge regarding the patient condition": "a173a340-9dee-4115-a901-b4555e546500",
    "Treatment plan issues": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "1.4.1.Treatment plan issues": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "Treatment plan not followed": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "1.4.2 Treatment plan not followed": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "Ineffective treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "1.4.3.Ineffective treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "Inadequate pain management": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "1.4.4.Inadequate pain management": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "Patient Discharged before completing treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "1.4.5.Patient Discharged before completing treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "Prescribing errors": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.1.Prescribing errors": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "No medication prescribed": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.3.No medication prescribed": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Dispensing medication without prescription": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.5.Dispensing medication without prescription": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Prescription of expired medication": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.6.Prescription of expired medication": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Medication shortages": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.8.Medication shortages": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Insufficient medication prescribed": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.4 Insufficient medication prescribed": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Errors in lab results": "9335435e-98fb-48cd-b153-102ce4f5a39d",
    "1.5.2.Errors in lab results": "9335435e-98fb-48cd-b153-102ce4f5a39d",
    "Errors in Pre-marriage lab test": "9335435e-98fb-48cd-b153-102ce4f5a39d",
    "1.5.4.Errors in Pre-marriage lab test": "9335435e-98fb-48cd-b153-102ce4f5a39d",
    "Equipment failure/malfunction": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "1.Equipment failure/malfunction": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "2.2.1.Equipment failure/malfunction": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "11.Heating, Ventilation, Air condition (HVAC) Failure": "aeda737e-3d7f-49d5-afa7-9b79f94a049f",
    "Wrong treatment": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "2.2.4.Wrong treatment": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "Poor hand-hygiene": "cb7032f8-cb95-4d2c-81d6-d1f0e4119800",
    "2.3.4.Poor hand-hygiene": "cb7032f8-cb95-4d2c-81d6-d1f0e4119800",
    "Improper practice of infection control recommendation": "cb7032f8-cb95-4d2c-81d6-d1f0e4119800",
    "2.3.5.Improper practice of infection control recommendation": "cb7032f8-cb95-4d2c-81d6-d1f0e4119800",
    "Paperwork delays": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.1.1.Paperwork delays": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Facility guidelines compliance": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.1.3.Facility guidelines compliance": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Required Service not obtained": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.1.4.Required Service not obtained": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Non-compliance with visiting hours policy": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.1.7.Non-compliance with visiting hours policy": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Inadequate reception service": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.1.8.Inadequate reception service": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Inadequate call center service": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.1.9.Inadequate call center service": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Poor environment": "7108f73c-300e-4212-939f-64264721888c",
    "3.2.1.Poor environment": "7108f73c-300e-4212-939f-64264721888c",
    "Poor cleanliness/sanitizing": "7108f73c-300e-4212-939f-64264721888c",
    "3.2.2.Poor cleanliness/sanitizing": "7108f73c-300e-4212-939f-64264721888c",
    "Poor Food service": "7108f73c-300e-4212-939f-64264721888c",
    "2.4.Poor Food service": "7108f73c-300e-4212-939f-64264721888c",
    "3.2.4.Poor Food service": "7108f73c-300e-4212-939f-64264721888c",
    "Poor security response": "86f5fdac-df2a-4d4a-a97a-47812e14489a",
    "3.3.2.Poor security response": "86f5fdac-df2a-4d4a-a97a-47812e14489a",
    "Theft and lost": "86f5fdac-df2a-4d4a-a97a-47812e14489a",
    "3.3.8.Theft and lost": "86f5fdac-df2a-4d4a-a97a-47812e14489a",
    "Lack of parking slots": "86f5fdac-df2a-4d4a-a97a-47812e14489a",
    "3.3.9.Lack of parking slots": "86f5fdac-df2a-4d4a-a97a-47812e14489a",
    "Miscalculation": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "3.4.2.Miscalculation": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "Pricing variations": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "3.4.5.Pricing variations": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "Unavailable Beds": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",
    "3.6.5.Unavailable Beds": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",
    "Sick leave issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.7.7.Sick leave issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Birth registry issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.7.4.Birth registry issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.7.5.Death registry issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.7.6.Lab results issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Medical report issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.7.3.Medical report issues": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Incorrect medical records": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "3.7.2.Incorrect medical records": "30ff5d01-cd94-49b4-9d62-e10ffba5faca",
    "Poor availability and scheduling": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "2.Poor availability and scheduling": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "4.1.2.Poor availability and scheduling": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "Appointment scheduling refusal": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "4.1.1.Appointment scheduling refusal": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "Appointment delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.1.4.Appointment delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Appointment cancellation": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.1.5.Appointment cancellation": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Scheduling errors": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.1.7.Scheduling errors": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Patient admission refusal": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.1.3.Patient admission refusal": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Delay in admitting patient": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.1.Delay in admitting patient": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Examination delay in emergency": "af9f4297-7094-416b-a9b2-b5d1b3f212c3",
    "Diagnosis delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.4.Diagnosis delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Delayed test result": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.5.Delayed test result": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Treatment delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.6.Treatment delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Surgical intervention delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.7.Surgical intervention delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Vaccinating delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.8.Vaccinating delay": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Delay in discharging patient": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.3.9.Delay in discharging patient": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "Communication of wrong information": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "5.2.2.Communication of wrong information": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "Deficient Information": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "5.2.1.Deficient Information": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "2.1.Deficient Information": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Not involving patient in clinical decisions": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "5.1.3.Not involving patient in clinical decisions": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "Failure to clarify patient case to his family": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "5.1.4.Failure to clarify patient case to his family": "17c5f8f1-e4c2-477a-a4d0-d4253434d22e",
    "Breach of patient privacy": "98ededd1-d7c3-440a-805e-addcedf1cb41",
    "6.3.2.Breach of patient privacy": "98ededd1-d7c3-440a-805e-addcedf1cb41",
    "No apology to the patient": "51087d24-2803-448e-a9dc-aba310fcc15b",
    "6.2.5.No apology to the patient": "51087d24-2803-448e-a9dc-aba310fcc15b",
    "Reimbursements issues": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "3.4.4.Reimbursements issues": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "Specialty not available": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",
    "3.5.2.Specialty not available": "2b67dc2f-b7d8-48a8-8e8c-4f90a571c414",
    "Patient death": "998e7952-ad30-432e-9631-e4493ed8aaa1",
    "2.2.18.Patient death": "998e7952-ad30-432e-9631-e4493ed8aaa1",
    "Labor and delivery related issues": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "2.2.10.Labor and delivery related issues": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "Wrong surgery": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "2.2.11.Wrong surgery": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "Surgical complications": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "2.2.13.Surgical complications": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "Complications resulting from treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "2.2.5.Complications resulting from treatment": "df5c295d-d04a-4260-a20e-ef2e9967d84f",
    "Vaccination shortages": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.10.Vaccination shortages": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Vaccinations timing": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.11.Vaccinations timing": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Refusal to vaccinate": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.12.Refusal to vaccinate": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Refusal to dispense medications": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "2.1.9.Refusal to dispense medications": "287ba991-305b-4585-bd3a-1bf2c8b19397",
    "Rushed, not time to see patients": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",
    "1.3.5.Rushed, not time to see patients": "bd4e9fea-cfe9-4a2d-9c34-0dcfad39129e",
    "Medical device failure": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "2.2.2.Medical device failure": "1faf00f0-9e44-4bc8-a83c-c1a3dcb89041",
    "Calculate Additional amount": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "3.4.3.Calculate Additional amount": "7f87c9c4-68df-48e7-81a4-4bebd7376253",
    "Patient referral refusal": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "4.4.1.Patient referral refusal": "b603082c-0e6a-420b-8f99-7ad8a5f9bbc8",
    "Delay in patient transfer": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
    "4.4.2.Delay in patient transfer": "00fcedd7-5de7-44dc-bf72-8fa62bbfcf4b",
}


def _normalize_name(name: str) -> str:
    """Normalize category name: replace newlines with spaces, collapse multiple spaces, strip."""
    return re.sub(r"\s+", " ", name.strip()) if name else ""


def get_mapped_category(name: str, mapping: dict) -> str:
    """
    Get UUID for a category name from the mapping.

    Args:
        name: The Excel category name
        mapping: The appropriate mapping dictionary

    Returns:
        UUID string or None if not mapped
    """
    if not name:
        return None

    normalized = _normalize_name(name)

    # Try exact match
    if normalized in mapping:
        return mapping[normalized]

    # Try with stripped number prefix (e.g., "1. Quality" -> "Quality", ".1. Quality" -> "Quality")
    stripped_name = re.sub(r"^[.\d]+\s*", "", normalized).strip()
    if stripped_name in mapping:
        return mapping[stripped_name]

    # Try case-insensitive match
    normalized_lower = normalized.lower()
    for key, value in mapping.items():
        if _normalize_name(key).lower() == normalized_lower:
            return value

    # Try case-insensitive with stripped name
    stripped_lower = stripped_name.lower()
    for key, value in mapping.items():
        if _normalize_name(re.sub(r"^[.\d]+\s*", "", key)).lower() == stripped_lower:
            return value

    return None


def is_taxonomy_mapped(domain: str, category: str, subcategory: str, classification: str) -> bool:
    """
    Check if all taxonomy levels are mapped.

    Args:
        domain: Domain name from Excel
        category: Category name from Excel
        subcategory: Sub-category name from Excel
        classification: Classification name from Excel

    Returns:
        True if all levels are mapped, False otherwise
    """
    # Check each level - if name exists but not mapped, return False
    if domain and not get_mapped_category(domain, DOMAIN_MAPPING):
        return False
    if category and not get_mapped_category(category, CATEGORY_MAPPING):
        return False
    if subcategory and not get_mapped_category(subcategory, SUBCATEGORY_MAPPING):
        return False
    if classification and not get_mapped_category(classification, CLASSIFICATION_MAPPING):
        return False

    return True
