
# Earlier releases of the outpatient activity data series did not
# have geography_level attribute. In order to create aggregates for data
# validation, we need to know which are groups and which are individual
# providers.
NATIONAL_CODES = {
    "All": "England",
    "ENG": "England",
}

REGIONAL_CODES = {
    "Y": "Unknown",
    "-": "Unknown",
    "Y56": "LONDON COMMISSIONING REGION",
    "Y58": "SOUTH WEST COMMISSIONING REGION",
    "Y59": "SOUTH EAST COMMISSIONING REGION",
    "Y60": "MIDLANDS COMMISSIONING REGION",
    "Y61": "EAST OF ENGLAND COMMISSIONING REGION",
    "Y62": "NORTH WEST COMMISSIONING REGION",
    "Y63": "NORTH EAST AND YORKSHIRE COMMISSIONING REGION",
    "Q99": "Wales",
}


# for the purposes of validating parsing the earlier xlsx files
# these are the mappings that a per-year outpatient activity data series
# must have to be considered valid
OP_MEASURE_TYPE_VALID_PERMS = [
    ("Attendance Summary by Gender", "Attended-Female"),
    ("Attendance Summary by Gender", "Attended-Male"),
    ("Attendance Summary by Gender", "Attended-Unknown Gender"),
    ("Attendance Summary by Gender", "DNA-Female"),
    ("Attendance Summary by Gender", "DNA-Male"),
    ("Attendance Summary by Gender", "DNA-Unknown Gender"),
    ("Attendance Summary by Gender", "Patient Cancelled-Female"),
    ("Attendance Summary by Gender", "Patient Cancelled-Male"),
    ("Attendance Summary by Gender", "Patient Cancelled-Unknown Gender"),
    ("Attendance Summary by Gender", "Hospital Cancelled-Female"),
    ("Attendance Summary by Gender", "Hospital Cancelled-Male"),
    ("Attendance Summary by Gender", "Hospital Cancelled-Unknown Gender"),
    ("Attendance Summary by Gender", "Unknown Outcome-Female"),
    ("Attendance Summary by Gender", "Unknown Outcome-Male"),
    ("Attendance Summary by Gender", "Unknown Outcome-Unknown Gender"),
    ("Attendance Type", "Attended first appointment"),
    ("Attendance Type", "Attended first tele consultation"),
    ("Attendance Type", "Attended subsequent appointment"),
    ("Attendance Type", "Attended subsequent tele consultation"),
    ("Attendance Type", "Attended but first/subsequent/tele unknown"),
    ("Attendance Type", "Did not attend first appointment"),
    ("Attendance Type", "Did not attend first tele consultation"),
    ("Attendance Type", "Did not attend subsequent appointment"),
    ("Attendance Type", "Did not attend subsequent tele consultation"),
    ("Attendance Type", "Did not attend, first/ subsequent/ tele unknown"),
    ("Attendance Type", "Patient cancelled first appointment"),
    ("Attendance Type", "Patient cancelled first tele consultation"),
    ("Attendance Type", "Patient cancelled subsequent appointment"),
    ("Attendance Type", "Patient cancelled subsequent tele consultation"),
    (
        "Attendance Type",
        "Patient cancelled appointment, first/ subsequent/ tele unknown",
    ),
    ("Attendance Type", "Hospital postponed/ cancelled first appointment"),
    ("Attendance Type", "Hospital postponed/ cancelled first tele consultation"),
    ("Attendance Type", "Hospital postponed/ cancelled subsequent appointment"),
    ("Attendance Type", "Hospital postponed/ cancelled subsequent tele consultation"),
    (
        "Attendance Type",
        "Hospital postponed/ cancelled appointment, first/ subsequent/ tele unknown",
    ),
    ("Attendance Type", "Unknown"),
    ("Attendances by selected main specialty", "Cardiology"),
    ("Attendances by selected main specialty", "Clinical Haematology"),
    ("Attendances by selected main specialty", "Dermatology"),
    ("Attendances by selected main specialty", "Ear, Nose & Throat (ENT)"),
    ("Attendances by selected main specialty", "Gynaecology"),
    ("Attendances by selected main specialty", "Obstetrics"),
    ("Attendances by selected main specialty", "Ophthalmology"),
    ("Attendances by selected main specialty", "Paediatrics"),
    ("Attendances by selected main specialty", "Rheumatology"),
    ("Attendances by selected main specialty", "Trauma & Orthopaedics"),
    ("Attended Appointments by Age Group", "10-19"),
    ("Attended Appointments by Age Group", "00-09"),
    ("Attended Appointments by Age Group", "20-29"),
    ("Attended Appointments by Age Group", "30-39"),
    ("Attended Appointments by Age Group", "40-49"),
    ("Attended Appointments by Age Group", "50-59"),
    ("Attended Appointments by Age Group", "60-69"),
    ("Attended Appointments by Age Group", "70-79"),
    ("Attended Appointments by Age Group", "80-89"),
    ("Attended Appointments by Age Group", "90+"),
    ("Attended Appointments by Age Group", "Unknown"),
    ("Did not Attend by Age Group", "10-19"),
    ("Did not Attend by Age Group", "00-09"),
    ("Did not Attend by Age Group", "20-29"),
    ("Did not Attend by Age Group", "30-39"),
    ("Did not Attend by Age Group", "40-49"),
    ("Did not Attend by Age Group", "50-59"),
    ("Did not Attend by Age Group", "60-69"),
    ("Did not Attend by Age Group", "70-79"),
    ("Did not Attend by Age Group", "80-89"),
    ("Did not Attend by Age Group", "90+"),
    ("Did not Attend by Age Group", "Unknown"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "Same Day"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "Under 1 Month"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "1-2 Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "2-3 Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "3-6 Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "6-9 Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "9-12 Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "12-18 Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "18+ Months"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "Unknown"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "Mean"),
    ("First Att from GP & Dental Practitioner refs by Waiting Time", "Median"),
    ("First Attendances by Outcome", "Another appointment given"),
    ("First Attendances by Outcome", "Appointment to be made at later date"),
    (
        "First Attendances by Outcome",
        "Discharged from consultants care (last attendance)",
    ),
    ("First Attendances by Outcome", "Unknown"),
    (
        "First Attendances by Source of Referral",
        "From a consultant, other than in an A&E department",
    ),
    ("First Attendances by Source of Referral", "General medical practitioner"),
    ("First Attendances by Source of Referral", "Other"),
    ("First Attendances by Source of Referral", "Referred from A&E department"),
    ("First Attendances by Source of Referral", "Unknown"),
]

# This is legacy. It's the column names in the Excel files that represent
# aggregtes, that are not present in the later csv files. They are useful for
# integrity checking that our totals match the Excel files.
# Unfortunately the originals have some em-dash and nbsp; in them which
# makes them hard to match visually
EXCEL_OP_DROPS = [
    "Table 1:Attendances - Total",
    "Table 1:DNAs - Total",
    "Table 1:Patient cancellations - Total",
    "Table 1:Hospital cancellations - Total",
    "Table 1:Unknown - Total",
    "Table 1:Total - Males",
    "Table 1:Total - Females",
    "Table 1:Total - Total",
    "Table 2:Attendances - Total",
    "Table 2:DNAs - Total",
    "Table 2:Patient cancellations - Total",
    "Table 2:Hospital cancellations - Total",
    "Table 3:Attended by age group (Total)",
    "Table 4:Did not attend by age group (Total)",
    "Table 5:Source of referral - Total",
    "Table 6:First attendance outcome - Total",
    "Table 2a: Attendances - First Attendance",
    "Table 2a: Attendances - Subsequent Attendance",
    "Table 2a: Attendances - Follow up attendances to each first attendance",
]

# Map of the Excel columns to the new measure_type/measure attributes for
# use in melting the wide data to long format.
EXCEL_OP_MAPS = {
    "Table 1:Attendances - Males": "Attendance Summary by Gender:Attended-Male",
    "Table 1:Attendances - Females": "Attendance Summary by Gender:Attended-Female",
    "Table 1:Attendances - Unknown": "Attendance Summary by Gender:Attended-Unknown Gender",
    "Table 1:DNAs - Males": "Attendance Summary by Gender:DNA-Male",
    "Table 1:DNAs - Females": "Attendance Summary by Gender:DNA-Female",
    "Table 1:DNAs - Unknown": "Attendance Summary by Gender:DNA-Unknown Gender",
    "Table 1:Patient cancellations - Males": "Attendance Summary by Gender:Patient Cancelled-Male",
    "Table 1:Patient cancellations - Females": "Attendance Summary by Gender:Patient Cancelled-Female",
    "Table 1:Patient cancellations - Unknown": "Attendance Summary by Gender:Patient Cancelled-Unknown Gender",
    "Table 1:Hospital cancellations - Males": "Attendance Summary by Gender:Hospital Cancelled-Male",
    "Table 1:Hospital cancellations - Females": "Attendance Summary by Gender:Hospital Cancelled-Female",
    "Table 1:Hospital cancellations - Unknown": "Attendance Summary by Gender:Hospital Cancelled-Unknown Gender",
    "Table 1:Unknown - Males": "Attendance Summary by Gender:Unknown Outcome-Male",
    "Table 1:Unknown - Females": "Attendance Summary by Gender:Unknown Outcome-Female",
    "Table 1:Unknown - Unknown": "Attendance Summary by Gender:Unknown Outcome-Unknown Gender",
    "Table 2:Attendances - Attended first appointment": "Attendance Type:Attended first appointment",
    "Table 2:Attendances - Attended first tele consultation": "Attendance Type:Attended first tele consultation",
    "Table 2:Attendances - Attended subsequent appointment": "Attendance Type:Attended subsequent appointment",
    "Table 2:Attendances - Attended subsequent tele consultation": "Attendance Type:Attended subsequent tele consultation",
    "Table 2:Attendances - Attended but first/subsequent/tele unknown": "Attendance Type:Attended but first/subsequent/tele unknown",
    "Table 2:DNAs - Did not attend first appointment": "Attendance Type:Did not attend first appointment",
    "Table 2:DNAs - Did not attend first tele consultation": "Attendance Type:Did not attend first tele consultation",
    "Table 2:DNAs - Did not attend subsequent appointment": "Attendance Type:Did not attend subsequent appointment",
    "Table 2:DNAs - Did not attend subsequent tele consultation": "Attendance Type:Did not attend subsequent tele consultation",
    "Table 2:DNAs - Did not attend, first/ subsequent/ tele unknown": "Attendance Type:Did not attend, first/ subsequent/ tele unknown",
    "Table 2:Patient cancellations - Patient cancelled first appointment": "Attendance Type:Patient cancelled first appointment",
    "Table 2:Patient cancellations - Patient cancelled first tele consultation": "Attendance Type:Patient cancelled first tele consultation",
    "Table 2:Patient cancellations - Patient cancelled subsequent appointment": "Attendance Type:Patient cancelled subsequent appointment",
    "Table 2:Patient cancellations - Patient cancelled subsequent tele consultation": "Attendance Type:Patient cancelled subsequent tele consultation",
    "Table 2:Patient cancellations - Patient cancelled appointment, first/ subsequent/ tele unknown": "Attendance Type:Patient cancelled appointment, first/ subsequent/ tele unknown",
    "Table 2:Hospital cancellations - Hospital postponed/ cancelled first appointment": "Attendance Type:Hospital postponed/ cancelled first appointment",
    "Table 2:Hospital cancellations - Hospital postponed/ cancelled first tele consultation": "Attendance Type:Hospital postponed/ cancelled first tele consultation",
    "Table 2:Hospital cancellations - Hospital postponed/ cancelled subsequent appointment": "Attendance Type:Hospital postponed/ cancelled subsequent appointment",
    "Table 2:Hospital cancellations - Hospital postponed/ cancelled subsequent tele consultation": "Attendance Type:Hospital postponed/ cancelled subsequent tele consultation",
    "Table 2:Hospital cancellations - Hospital postponed/ cancelled appointment, first/ subsequent/ tele unknown": "Attendance Type:Hospital postponed/ cancelled appointment, first/ subsequent/ tele unknown",
    "Table 2:Unknown - Not known": "Attendance Type:Unknown",
    "Table 3:Attended by age group    (0-9)": "Attended Appointments by Age Group:00-09",
    "Table 3:Attended by age group (10-19)": "Attended Appointments by Age Group:10-19",
    "Table 3:Attended by age group (20-29)": "Attended Appointments by Age Group:20-29",
    "Table 3:Attended by age group (30-39)": "Attended Appointments by Age Group:30-39",
    "Table 3:Attended by age group (40-49)": "Attended Appointments by Age Group:40-49",
    "Table 3:Attended by age group (50-59)": "Attended Appointments by Age Group:50-59",
    "Table 3:Attended by age group (60-69)": "Attended Appointments by Age Group:60-69",
    "Table 3:Attended by age group (70-79)": "Attended Appointments by Age Group:70-79",
    "Table 3:Attended by age group (80-89)": "Attended Appointments by Age Group:80-89",
    "Table 3:Attended by age group (90+)": "Attended Appointments by Age Group:90+",
    "Table 3:Attended by age group (unknown)": "Attended Appointments by Age Group:Unknown",
    "Table 4:Did not attend by age group  (0-9)": "Did not Attend by Age Group:00-09",
    "Table 4:Did not attend by age group  (10-19)": "Did not Attend by Age Group:10-19",
    "Table 4:Did not attend by age group  (20-29)": "Did not Attend by Age Group:20-29",
    "Table 4:Did not attend by age group  (30-39)": "Did not Attend by Age Group:30-39",
    "Table 4:Did not attend by age group  (40-49)": "Did not Attend by Age Group:40-49",
    "Table 4:Did not attend by age group  (50-59)": "Did not Attend by Age Group:50-59",
    "Table 4:Did not attend by age group  (60-69)": "Did not Attend by Age Group:60-69",
    "Table 4:Did not attend by age group  (70-79)": "Did not Attend by Age Group:70-79",
    "Table 4:Did not attend by age group  (80-89)": "Did not Attend by Age Group:80-89",
    "Table 4:Did not attend by age group (90+)": "Did not Attend by Age Group:90+",
    "Table 4:Did not attend by age group (unknown)": "Did not Attend by Age Group:Unknown",
    "Table 5:Source of referral - General medical practitioner": "First Attendances by Source of Referral:General medical practitioner",
    "Table 5:Source of referral - Referred from A&E department": "First Attendances by Source of Referral:Referred from A&E department",
    "Table 5:Source of referral - From a consultant, other than in an A&E department": "First Attendances by Source of Referral:From a consultant, other than in an A&E department",
    "Table 5:Source of referral - Other source of referral": "First Attendances by Source of Referral:Other",
    "Table 5:Source of referral - Unknown": "First Attendances by Source of Referral:Unknown",
    "Table 6:First attendance outcome - Discharged from consultants care (last attendance)": "First Attendances by Outcome:Discharged from consultants care (last attendance)",
    "Table 6:First attendance outcome - Another appointment given": "First Attendances by Outcome:Another appointment given",
    "Table 6:First attendance outcome - Appointment to be made at later date": "First Attendances by Outcome:Appointment to be made at later date",
    "Table 6:First attendance outcome - Unknown": "First Attendances by Outcome:Unknown",
    "Table 7:First appointment by time waited (Same day)": "First Att from GP & Dental Practitioner refs by Waiting Time:Same Day",
    "Table 7:First appointment by time waited (Under 1 month)": "First Att from GP & Dental Practitioner refs by Waiting Time:Under 1 Month",
    "Table 7:First appointment by time waited (1 under 2 months)": "First Att from GP & Dental Practitioner refs by Waiting Time:1-2 Months",
    "Table 7:First appointment by time waited (2 under 3 months)": "First Att from GP & Dental Practitioner refs by Waiting Time:2-3 Months",
    "Table 7:First appointment by time waited (3 -under 6 months)": "First Att from GP & Dental Practitioner refs by Waiting Time:3-6 Months",
    "Table 7:First appointment by time waited (6 -under 9 months)": "First Att from GP & Dental Practitioner refs by Waiting Time:6-9 Months",
    "Table 7:First appointment by time waited (9 mon -under 1 year)": "First Att from GP & Dental Practitioner refs by Waiting Time:9-12 Months",
    "Table 7:First appointment by time waited (1 year -under 18 months)": "First Att from GP & Dental Practitioner refs by Waiting Time:12-18 Months",
    "Table 7:First appointment by time waited (18 months and over)": "First Att from GP & Dental Practitioner refs by Waiting Time:18+ Months",
    "Table 7:First appointment by time waited (Total)": "First Att from GP & Dental Practitioner refs by Waiting Time:Unknown",
    "Table 7:First appointment by time waited (Mean waiting time)": "First Att from GP & Dental Practitioner refs by Waiting Time:Mean",
    "Table 7:First appointment by time waited (Median waiting time)": "First Att from GP & Dental Practitioner refs by Waiting Time:Median",
    "Table 8:Attendance by main specialty - Trauma & Orthopaedics": "Attendances by selected main specialty:Trauma & Orthopaedics",
    "Table 8:Attendance by main specialty- Ear, nose and throat (ENT)": "Attendances by selected main specialty:Ear, Nose & Throat (ENT)",
    "Table 8:Attendance by main specialty- Opthhamology": "Attendances by selected main specialty:Ophthalmology",
    "Table 8:Attendance by main specialty - Clinical haemotology": "Attendances by selected main specialty:Clinical Haematology",
    "Table 8:Attendance by main specialty - Cardiology": "Attendances by selected main specialty:Cardiology",
    "Table 8:Attendance by main specialty - Dermatology": "Attendances by selected main specialty:Dermatology",
    "Table 8:Attendance by main specialty - Rheumatology": "Attendances by selected main specialty:Rheumatology",
    "Table 8:Attendance by main specialty - Paediatrics": "Attendances by selected main specialty:Paediatrics",
    "Table 8:Attendance by main specialty - Obstetrics": "Attendances by selected main specialty:Obstetrics",
    "Table 8:Attendance by main specialty - Gynaecology": "Attendances by selected main specialty:Gynaecology",
}
