###############################################################################
# Copyright 2015 University of Florida. All rights reserved.
# This file is part of the BlueButton.py project.
# Use of this source code is governed by the license found in the LICENSE file.
###############################################################################

"""/*
 * Administrative Gender (HL7 V3)
 * http://phinvads.cdc.gov/vads/ViewValueSet.action?id=8DE75E17-176B-DE11-9B52-0015173D1785
 * OID: 2.16.840.1.113883.1.11.1
 */"""
GENDER_MAP = {
  'F': 'female',
  'M': 'male',
  'UN': 'undifferentiated'
}

"""/*
 * Marital Status (HL7)
 * http://phinvads.cdc.gov/vads/ViewValueSet.action?id=46D34BBC-617F-DD11-B38D-00188B398520
 * OID: 2.16.840.1.114222.4.11.809
 */"""
MARITAL_STATUS_MAP = {
  'N': 'annulled',
  'C': 'common law',
  'D': 'divorced',
  'P': 'domestic partner',
  'I': 'interlocutory',
  'E': 'legally separated',
  'G': 'living together',
  'M': 'married',
  'O': 'other',
  'R': 'registered domestic partner',
  'A': 'separated',
  'S': 'single',
  'U': 'unknown',
  'B': 'unmarried',
  'T': 'unreported',
  'W': 'widowed'
}

"""/*
 * Religious Affiliation (HL7 V3)
 * https://phinvads.cdc.gov/vads/ViewValueSet.action?id=6BFDBFB5-A277-DE11-9B52-0015173D1785
 * OID: 2.16.840.1.113883.5.1076
 */"""
RELIGION_MAP = {
  "1001": "adventist",
  "1002": "african religions",
  "1003": "afro-caribbean religions",
  "1004": "agnosticism",
  "1005": "anglican",
  "1006": "animism",
  "1061": "assembly of god",
  "1007": "atheism",
  "1008": "babi & baha'i faiths",
  "1009": "baptist",
  "1010": "bon",
  "1062": "brethren",
  "1011": "cao dai",
  "1012": "celticism",
  "1013": "christian (non-catholic, non-specific)",
  "1063": "christian scientist",
  "1064": "church of christ",
  "1065": "church of god",
  "1014": "confucianism",
  "1066": "congregational",
  "1015": "cyberculture religions",
  "1067": "disciples of christ",
  "1016": "divination",
  "1068": "eastern orthodox",
  "1069": "episcopalian",
  "1070": "evangelical covenant",
  "1017": "fourth way",
  "1018": "free daism",
  "1071": "friends",
  "1072": "full gospel",
  "1019": "gnosis",
  "1020": "hinduism",
  "1021": "humanism",
  "1022": "independent",
  "1023": "islam",
  "1024": "jainism",
  "1025": "jehovah's witnesses",
  "1026": "judaism",
  "1027": "latter day saints",
  "1028": "lutheran",
  "1029": "mahayana",
  "1030": "meditation",
  "1031": "messianic judaism",
  "1073": "methodist",
  "1032": "mitraism",
  "1074": "native american",
  "1075": "nazarene",
  "1033": "new age",
  "1034": "non-roman catholic",
  "1035": "occult",
  "1036": "orthodox",
  "1037": "paganism",
  "1038": "pentecostal",
  "1076": "presbyterian",
  "1039": "process, the",
  "1077": "protestant",
  "1078": "protestant, no denomination",
  "1079": "reformed",
  "1040": "reformed/presbyterian",
  "1041": "roman catholic church",
  "1080": "salvation army",
  "1042": "satanism",
  "1043": "scientology",
  "1044": "shamanism",
  "1045": "shiite (islam)",
  "1046": "shinto",
  "1047": "sikism",
  "1048": "spiritualism",
  "1049": "sunni (islam)",
  "1050": "taoism",
  "1051": "theravada",
  "1081": "unitarian universalist",
  "1052": "unitarian-universalism",
  "1082": "united church of christ",
  "1053": "universal life church",
  "1054": "vajrayana (tibetan)",
  "1055": "veda",
  "1056": "voodoo",
  "1057": "wicca",
  "1058": "yaohushua",
  "1059": "zen buddhism",
  "1060": "zoroastrianism"
}

"""/*
 * Race & Ethnicity (HL7 V3)
 * Full list at http://phinvads.cdc.gov/vads/ViewCodeSystem.action?id=2.16.840.1.113883.6.238
 * OID: 2.16.840.1.113883.6.238
 *
 * Abbreviated list closer to real usage at: (Race / Ethnicity)
 * https://phinvads.cdc.gov/vads/ViewValueSet.action?id=67D34BBC-617F-DD11-B38D-00188B398520
 * https://phinvads.cdc.gov/vads/ViewValueSet.action?id=35D34BBC-617F-DD11-B38D-00188B398520
 */"""
RACE_ETHNICITY_MAP = {
  '2028-9': 'asian',
  '2054-5': 'black or african american',
  '2135-2': 'hispanic or latino',
  '2076-8': 'native',
  '2186-5': 'not hispanic or latino',
  '2131-1': 'other',
  '2106-3': 'white'
}

"""/*
 * Role (HL7 V3)
 * https://phinvads.cdc.gov/vads/ViewCodeSystem.action?id=2.16.840.1.113883.5.111
 * OID: 2.16.840.1.113883.5.111
 */"""
ROLE_MAP = {
  "ACC": "accident site",
  "ACHFID":  "accreditation location identifier",
  "ACTMIL":  "active duty military",
  "ALL": "allergy clinic",
  "AMB": "ambulance",
  "AMPUT":   "amputee clinic",
  "ANTIBIOT":    "antibiotic",
  "ASSIST":  "assistive non-person living subject",
  "AUNT":    "aunt",
  "B":   "blind",
  "BF":  "beef",
  "BILL":    "billing contact",
  "BIOTH":   "biotherapeutic non-person living subject",
  "BL":  "broiler",
  "BMTC":    "bone marrow transplant clinic",
  "BMTU":    "bone marrow transplant unit",
  "BR":  "breeder",
  "BREAST":  "breast clinic",
  "BRO": "brother",
  "BROINLAW":    "brother-in-law",
  "C":   "calibrator",
  "CANC": "child and adolescent neurology clinic",
  "CAPC": "child and adolescent psychiatry clinic",
  "CARD": "ambulatory health care facilities; clinic/center; rehabilitation: cardiac facilities",
  "CAS": "asylum seeker",
  "CASM":    "single minor asylum seeker",
  "CATH":    "cardiac catheterization lab",
  "CCO": "clinical companion",
  "CCU": "coronary care unit",
  "CHEST":   "chest unit",
  "CHILD":   "child",
  "CHLDADOPT":   "adopted child",
  "CHLDFOST":    "foster child",
  "CHLDINLAW":   "child in-law",
  "CHR": "chronic care facility",
  "CLAIM":   "claimant",
  "CN":  "national",
  "CNRP":    "non-country member without residence permit",
  "CNRPM":   "non-country member minor without residence permit",
  "CO":  "companion",
  "COAG":    "coagulation clinic",
  "COCBEN":  "continuity of coverage beneficiary",
  "COMM":    "community location",
  "COMMUNITYLABORATORY": "community laboratory",
  "COUSN":   "cousin",
  "CPCA":    "permit card applicant",
  "CRIMEVIC":    "crime victim",
  "CRP": "non-country member with residence permit",
  "CRPM":    "non-country member minor with residence permit",
  "CRS": "colon and rectal surgery clinic",
  "CSC": "community service center",
  "CVDX":    "cardiovascular diagnostics or therapeutics unit",
  "DA":  "dairy",
  "DADDR":   "delivery address",
  "DAU": "natural daughter",
  "DAUADOPT":    "adopted daughter",
  "DAUC":    "daughter",
  "DAUFOST": "foster daughter",
  "DAUINLAW":    "daughter in-law",
  "DC":  "therapeutic class",
  "DEBR":    "debridement",
  "DERM":    "dermatology clinic",
  "DIFFABL": "differently abled",
  "DOMPART": "domestic partner",
  "DPOWATT": "durable power of attorney",
  "DR":  "draft",
  "DU":  "dual",
  "DX":  "diagnostics or therapeutics unit",
  "E":   "electronic qc",
  "ECHO":    "echocardiography lab",
  "ECON":    "emergency contact",
  "ENDO":    "endocrinology clinic",
  "ENDOS":   "endoscopy lab",
  "ENROLBKR":    "enrollment broker",
  "ENT": "otorhinolaryngology clinic",
  "EPIL":    "epilepsy unit",
  "ER":  "emergency room",
  "ERL": "enrollment",
  "ETU": "emergency trauma unit",
  "EXCEST":  "executor of estate",
  "EXT": "extended family member",
  "F":   "filler proficiency",
  "FAMDEP":  "family dependent",
  "FAMMEMB": "family member",
  "FI":  "fiber",
  "FMC": "family medicine clinic",
  "FRND":    "unrelated friend",
  "FSTUD":   "full-time student",
  "FTH": "father",
  "FTHINLAW":    "father-in-law",
  "FULLINS": "fully insured coverage sponsor",
  "G":   "group",
  "GACH":    "hospitals; general acute care hospital",
  "GD":  "generic drug",
  "GDF": "generic drug form",
  "GDS": "generic drug strength",
  "GDSF":    "generic drug strength form",
  "GGRFTH":  "great grandfather",
  "GGRMTH":  "great grandmother",
  "GGRPRN":  "great grandparent",
  "GI":  "gastroenterology clinic",
  "GIDX":    "gastroenterology diagnostics or therapeutics lab",
  "GIM": "general internal medicine clinic",
  "GRFTH":   "grandfather",
  "GRMTH":   "grandmother",
  "GRNDCHILD":   "grandchild",
  "GRNDDAU": "granddaughter",
  "GRNDSON": "grandson",
  "GRPRN":   "grandparent",
  "GT":  "guarantor",
  "GUADLTM": "guardian ad lidem",
  "GUARD":   "guardian",
  "GYN": "gynecology clinic",
  "HAND":    "hand clinic",
  "HANDIC":  "handicapped dependent",
  "HBRO":    "half-brother",
  "HD":  "hemodialysis unit",
  "HEM": "hematology clinic",
  "HLAB":    "hospital laboratory",
  "HOMEHEALTH":  "home health",
  "HOSP":    "hospital",
  "HPOWATT": "healthcare power of attorney",
  "HRAD":    "radiology unit",
  "HSIB":    "half-sibling",
  "HSIS":    "half-sister",
  "HTN": "hypertension clinic",
  "HU":  "hospital unit",
  "HUSB":    "husband",
  "HUSCS":   "specimen collection site",
  "ICU": "intensive care unit",
  "IEC": "impairment evaluation center",
  "INDIG":   "member of an indigenous people",
  "INFD":    "infectious disease clinic",
  "INJ": "injured plaintiff",
  "INJWKR":  "injured worker",
  "INLAB":   "inpatient laboratory",
  "INPHARM": "inpatient pharmacy",
  "INV": "infertility clinic",
  "JURID":   "jurisdiction location identifier",
  "L":   "pool",
  "LABORATORY":  "laboratory",
  "LOCHFID": "local location identifier",
  "LY":  "layer",
  "LYMPH":   "lympedema clinic",
  "MAUNT":   "maternalaunt",
  "MBL": "medical laboratory",
  "MCOUSN":  "maternalcousin",
  "MGDSF":   "manufactured drug strength form",
  "MGEN":    "medical genetics clinic",
  "MGGRFTH": "maternalgreatgrandfather",
  "MGGRMTH": "maternalgreatgrandmother",
  "MGGRPRN": "maternalgreatgrandparent",
  "MGRFTH":  "maternalgrandfather",
  "MGRMTH":  "maternalgrandmother",
  "MGRPRN":  "maternalgrandparent",
  "MHSP":    "military hospital",
  "MIL": "military",
  "MOBL":    "mobile unit",
  "MT":  "meat",
  "MTH": "mother",
  "MTHINLAW":    "mother-in-law",
  "MU":  "multiplier",
  "MUNCLE":  "maternaluncle",
  "NBOR":    "neighbor",
  "NBRO":    "natural brother",
  "NCCF":    "nursing or custodial care facility",
  "NCCS":    "neurology critical care and stroke unit",
  "NCHILD":  "natural child",
  "NEPH":    "nephrology clinic",
  "NEPHEW":  "nephew",
  "NEUR":    "neurology clinic",
  "NFTH":    "natural father",
  "NFTHF":   "natural father of fetus",
  "NIECE":   "niece",
  "NIENEPH": "niece/nephew",
  "NMTH":    "natural mother",
  "NOK": "next of kin",
  "NPRN":    "natural parent",
  "NS":  "neurosurgery unit",
  "NSIB":    "natural sibling",
  "NSIS":    "natural sister",
  "O":   "operator proficiency",
  "OB":  "obstetrics clinic",
  "OF":  "outpatient facility",
  "OMS": "oral and maxillofacial surgery clinic",
  "ONCL":    "medical oncology clinic",
  "OPH": "opthalmology clinic",
  "OPTC":    "optometry clinic",
  "ORG": "organizational contact",
  "ORTHO":   "orthopedics clinic",
  "OUTLAB":  "outpatient laboratory",
  "OUTPHARM":    "outpatient pharmacy",
  "P":   "patient",
  "PAINCL":  "pain clinic",
  "PATHOLOGIST": "pathologist",
  "PAUNT":   "paternalaunt",
  "PAYOR":   "payor contact",
  "PC":  "primary care clinic",
  "PCOUSN":  "paternalcousin",
  "PEDC":    "pediatrics clinic",
  "PEDCARD": "pediatric cardiology clinic",
  "PEDE":    "pediatric endocrinology clinic",
  "PEDGI":   "pediatric gastroenterology clinic",
  "PEDHEM":  "pediatric hematology clinic",
  "PEDHO":   "pediatric oncology clinic",
  "PEDICU":  "pediatric intensive care unit",
  "PEDID":   "pediatric infectious disease clinic",
  "PEDNEPH": "pediatric nephrology clinic",
  "PEDNICU": "pediatric neonatal intensive care unit",
  "PEDRHEUM":    "pediatric rheumatology clinic",
  "PEDU":    "pediatric unit",
  "PGGRFTH": "paternalgreatgrandfather",
  "PGGRMTH": "paternalgreatgrandmother",
  "PGGRPRN": "paternalgreatgrandparent",
  "PGRFTH":  "paternalgrandfather",
  "PGRMTH":  "paternalgrandmother",
  "PGRPRN":  "paternalgrandparent",
  "PH":  "policy holder",
  "PHARM":   "pharmacy",
  "PHLEBOTOMIST":    "phlebotomist",
  "PHU": "psychiatric hospital unit",
  "PL":  "pleasure",
  "PLS": "plastic surgery clinic",
  "POD": "podiatry clinic",
  "POWATT":  "power of attorney",
  "PRC": "pain rehabilitation center",
  "PREV":    "preventive medicine clinic",
  "PRN": "parent",
  "PRNINLAW":    "parent in-law",
  "PROCTO":  "proctology clinic",
  "PROFF":   "provider's office",
  "PROG":    "program eligible",
  "PROS":    "prosthodontics clinic",
  "PSI": "psychology clinic",
  "PSTUD":   "part-time student",
  "PSY": "psychiatry clinic",
  "PSYCHF":  "psychiatric care facility",
  "PT":  "patient",
  "PTRES":   "patient's residence",
  "PUNCLE":  "paternaluncle",
  "Q":   "quality control",
  "R":   "replicate",
  "RADDX":   "radiology diagnostics or therapeutics unit",
  "RADO":    "radiation oncology unit",
  "RC":  "racing",
  "RESPRSN": "responsible party",
  "RETIREE": "retiree",
  "RETMIL":  "retired military",
  "RH":  "rehabilitation hospital",
  "RHAT":    "addiction treatment center",
  "RHEUM":   "rheumatology clinic",
  "RHII":    "intellectual impairment center",
  "RHMAD":   "parents with adjustment difficulties center",
  "RHPI":    "physical impairment center",
  "RHPIH":   "physical impairment - hearing center",
  "RHPIMS":  "physical impairment - motor skills center",
  "RHPIVS":  "physical impairment - visual skills center",
  "RHU": "rehabilitation hospital unit",
  "RHYAD":   "youths with adjustment difficulties center",
  "RNEU":    "neuroradiology unit",
  "ROOM":    "roommate",
  "RTF": "residential treatment facility",
  "SCHOOL":  "school",
  "SCN": "screening",
  "SEE": "seeing",
  "SELF":    "self",
  "SELFINS": "self insured coverage sponsor",
  "SH":  "show",
  "SIB": "sibling",
  "SIBINLAW":    "sibling in-law",
  "SIGOTHR": "significant other",
  "SIS": "sister",
  "SISINLAW":    "sister-in-law",
  "SLEEP":   "sleep disorders unit",
  "SNF": "skilled nursing facility",
  "SNIFF":   "sniffing",
  "SON": "natural son",
  "SONADOPT":    "adopted son",
  "SONC":    "son",
  "SONFOST": "foster son",
  "SONINLAW":    "son in-law",
  "SPMED":   "sports medicine clinic",
  "SPON":    "sponsored dependent",
  "SPOWATT": "special power of attorney",
  "SPS": "spouse",
  "STPBRO":  "stepbrother",
  "STPCHLD": "step child",
  "STPDAU":  "stepdaughter",
  "STPFTH":  "stepfather",
  "STPMTH":  "stepmother",
  "STPPRN":  "step parent",
  "STPSIB":  "step sibling",
  "STPSIS":  "stepsister",
  "STPSON":  "stepson",
  "STUD":    "student",
  "SU":  "surgery clinic",
  "SUBJECT": "self",
  "SURF":    "substance use rehabilitation facility",
  "THIRDPARTY":  "third party",
  "TPA": "third party administrator",
  "TR":  "transplant clinic",
  "TRAVEL":  "travel and geographic medicine clinic",
  "TRB": "tribal member",
  "UMO": "utilization management organization",
  "UNCLE":   "uncle",
  "UPC": "underage protection center",
  "URO": "urology clinic",
  "V":   "verifying",
  "VET": "veteran",
  "VL":  "veal",
  "WARD":    "ward",
  "WIFE":    "wife",
  "WL":  "wool",
  "WND": "wound clinic",
  "WO":  "working",
  "WORK":    "work site",
}

PROBLEM_STATUS_MAP = {
  "55561003": "active",
  "73425007": "inactive",
  "413322009": "resolved"
}


def _lookup_function_generator(mapping):
    def fn(key):
        return mapping.get(key)
    return fn


gender = _lookup_function_generator(GENDER_MAP)
marital_status = _lookup_function_generator(MARITAL_STATUS_MAP)
