medicaid_utils.adapted_algorithms.py_nyu_billings package

Submodules

medicaid_utils.adapted_algorithms.py_nyu_billings.billings_ed module

Python implementation of The New York University (NYU) Emergency Department (ED) visit algorithm. This algorithm is the most widely used tool for retrospectively assessing the probability that ED visits are urgent, preventable, or optimally treated in an ED, using administrative data (Billings, Parikh, and Mijanovich 2000b; Feldman 2010).

class medicaid_utils.adapted_algorithms.py_nyu_billings.billings_ed.BillingsED[source]

Bases: object

This class packages functions to perform NYU/ Billings algorithm based classification of ED visits

cat = 'injury'
data_folder = '/home/runner/work/medicaid-utils/medicaid-utils/medicaid_utils/adapted_algorithms/py_nyu_billings/data'
dct_category_dx_codes = {'acs': ['033', '390', '391', '037', '045', '345', '481', '483', '485', '486', '462', '463', '465', '011', '012', '013', '014', '015', '016', '017', '018', '491', '492', '494', '496', '493', '681', '682', '683', '686', '590', '260', '261', '262', '521', '522', '523', '525', '528', '382', '428', '413', '614', '7803', '4721', '2501', '2502', '2503', '2508', '2509', '2500', '2512', '5589', '5990', '5999', '2765', '2680', '2681', '4660', '4822', '4823', '4829', '5184', '4010', '4019', '4111', '4118', '3200', '2801', '2808', '2809', '7834', '7070', '7071', '7078', '7079', '40201', '40211', '40291', '40210', '40290', '40200'], 'alcohol': ['291', '303', '3050', '3575', '4255', '5353', '5710', '5712', '5713', '7903', 'V704', 'V113', 'V791', '76071'], 'drug': ['292', '304', '3052', '3053', '3054', '3055', '3056', '3057', '3058', '3059', '3576', '6483', '6555', '7795', '76072', '76073', '76075'], 'injury': ['8', '9', 'E8', 'E90', 'E91', 'E92', 'E93', 'E94', 'E96', 'E97', 'E98'], 'psych': ['290', '293', '294', '295', '296', '297', '298', '299', '300', '301', '302', '306', '307', '308', '309', '310', '311', '312', '313', '314', '315', '316', '317', '318', '319', 'E95', '6484', 'V110', 'V111', 'V112', 'V114', 'V115', 'V116', 'V117', 'V118', 'V119', 'V710', 'V790']}
dct_recode_non_startswith = {'0049': '0059', '0085': '0059', '0088': '0059', '0340': '462', '0380': '0381', '0389': '0381', '0542': '5280', '0579': '05700', '0740': '5280', '0792': '075', '0799': '075', '07999': '075', '1104': '1100', '1108': '1100', '1109': '1100', '1110': '1100', '1319': '13101', '25001': '25000', '25060': '25080', '25061': '25080', '25081': '25080', '25082': '25080', '25083': '25080', '2510': '2512', '2740': '2749', '2761': '2765', '2768': '2767', '28261': '28260', '28262': '28260', '2910': '29181', '29532': '29530', '29590': '29530', '2989': '29530', '30001': '30000', '3009': '30000', '30300': '30301', '30400': '30390', '30420': '30561', '30500': '30390', '30560': '30390', '3058': '30390', '30590': '30390', '3061': '30000', '30781': '7840', '3080': '3089', '3090': '311', '3469 ': '7840', '34690': '7840', '3559': '3549', '37200': '0779', '37203': '0779', '37214': '0779', '37230': '0779', '38100': '3814', '38101': '3829', '38200': '38110', '40291': '4019', '40391': '4019', '40493': '4019', '41001': '41091', '41011': '41091', '41021': '41091', '41041': '41091', '41071': '41091', '41090': '4111', '41400': '4149', '41401': '4149', '4260': '42613', '42732': '42731', '4279': '42789', '43311': '4359', '43401': '4359', '43411': '4359', '43491': '4359', '436': '4359', '4549': '4540', '4553': '4550', '4554': '4552', '4556': '4550', '4558': '4552', '460': '4660', '4610': '4619', '4620': '462', '463': '462', '4658': '4660', '4659': '4660', '4660': '4660', '4661': '46619', '46611': '46619', '4730': '4739', '4770': '4781', '4779': '4739', '4809': '485', '481': '485', '4821': '485', '4824': '485', '48283': '485', '48289': '485', '486': '485', '490': '4660', '5210': '5220', '5225': '5220', '5233': '5231', '5234': '5231', '5239': '5231', '5282': '5280', '53081': '5301', '53100': '5339', '53140': '5339', '53240': '5339', '53390': '5339', '53550': '53500', '5400': '541', '5401': '541', '5409': '541', '56081': '5609', '57400': '57420', '57410': '57420', '5750': '57420', '5770': '5772', '5771': '5772', '5889': '586', '5921': '5920', '5929': '5920', '5941': '5920', '5950': '5990', '5959': '5990', '59780': '0980', '6089': '6084', '6142': '6149', '6143': '6149', '6159': '6149', '61610': '6160', '6168': '6160', '6269': '6268', '6331': '6339', '6338': '6339', '63491': '63490', '63492': '63490', '64003': '64000', '64093': '64000', '64183': '64303', '64193': '64000', '64313': '64303', '64390': '64303', '64413': '64410', '6809': '6806', '68102': '68100', '68110': '68100', '68111': '68100', '6850': '6851', '6926': '6918', '6929': '6918', '7079': '7071', '70890': '7089', '71590': '71946', '71596': '71946', '71690': '71946', '71696': '71695', '71697': '71946', '71940': '71946', '71941': '71946', '71943': '71946', '71949': '71947', '7210': '7235', '7213': '7243', '72190': '7248', '72210': '7243', '7231': '7235', '7241': '7243', '7242': '7248', '7245': '7248', '72709': '72705', '73399': '7329', '7803': '78039', '78031': '78039', '78052': '78050', '7821': '6918', '78601': '30000', '78700': '7870', '78701': '7870', '78702': '7870', '78703': '7870', '7880': '5920', '78840': '7884', '78841': '7884', '78842': '7884', '78843': '7884', '7887': '0980', '7907': '0381', '8024': '8028', '80700': '80701', '80702': '80700', '80703': '80701', '81201': '81200', '81209': '81200', '81220': '81200', '81240': '81200', '81241': '81200', '81305': '81200', '81342': '81341', '81343': '81383', '81344': '81341', '81381': '81341', '81400': '81341', '81600': '81500', '81601': '81500', '81602': '81500', '82101': '82100', '82380': '82382', '82381': '82382', '8240': '8242', '8244': '8242', '8246': '8242', '8248': '8242', '8250': '82520', '82525': '82520', '8260': '82520', '83101': '83100', '83104': '83100', '83209': '83200', '8408': '8409', '8419': '8409', '84210': '84200', '84213': '84209', '8441': '8448', '8449': '8439', '84509': '84500', '84510': '84500', '8469': '8460', '8471': '8472', '8479': '8460', '8709': '8708', '87200': '87201', '87261': '38420', '8728': '87201', '8731': '8730', '87340': '87320', '87341': '87320', '87342': '87320', '87343': '87320', '87344': '87320', '87353': '87320', '87360': '87320', '87364': '87320', '8738': '8744', '8748': '8744', '8760': '8750', '8770': '8750', '88003': '88000', '88100': '88000', '88110': '88120', '8820': '88102', '8821': '8822', '8831': '8830', '8832': '8830', '8840': '88000', '8910': '8900', '8921': '8920', '8930': '8920', '9104': '9105', '9110': '9100', '9114': '9105', '9130': '9100', '9134': '9135', '9140': '9141', '9150': '9100', '9160': '9100', '9164': '9175', '9165': '9175', '9170': '9100', '9180': '9181', '9189': '9181', '9190': '9100', '9195': '9194', '9196': '9156', '9212': '920', '9213': '920', '9219': '920', '9222': '9221', '9223': '9221', '92232': '92231', '92310': '92300', '92311': '92300', '92320': '92300', '9233': '92300', '9238': '92300', '9239': '92300', '92401': '92400', '92411': '92400', '92420': '92400', '92421': '92400', '9243': '92400', '9245': '92400', '9330': '933', '9331': '933', '9351': '933', '938': '936', '9404': '9409', '94321': '94120', '94421': '94120', '94500': '94120', '94522': '94120', '94524': '94420', '94526': '94120', '9462': '94120', '9490': '94120', '9592': '9593', '9630': '9654', '9690': '9654', '9694': '9691', '9700': '9691', '99810': '9981', '99811': '9981', '99812': '9981', '99813': '9981', '9985': '99883', '99859': '99883', '99889': '99883', 'V589': 'V5889', 'V709': 'V708 ', 'v709': 'V708 '}
df_eddxs = prindx  nonemerg   emergpc  emedpa   emednpa 0     0030  0.000000  1.000000     0.0  0.000000 1     0059  0.371429  0.457143     0.0  0.171429 2     0090  1.000000  0.000000     0.0  0.000000 3    01190  0.000000  0.000000     1.0  0.000000 4    03400  0.000000  1.000000     0.0  0.000000 ..     ...       ...       ...     ...       ... 654   V718  1.000000  0.000000     0.0  0.000000 655   V719  1.000000  0.000000     0.0  0.000000 656    V72  1.000000  0.000000     0.0  0.000000 657   V741  1.000000  0.000000     0.0  0.000000 658   V802  1.000000  0.000000     0.0  0.000000  [659 rows x 5 columns]
filename = 'billings_ed.py'
classmethod get_nyu_ed_categories(dx_code: str) Tuple[int, int, int, int, int, int, float, float, float, float][source]

Returns probabilities for each of the NYU ED categories, based on the input diagnosis code

Parameters:

dx_code (str) – Diagnosis code

Returns:

  • unclassified (int) – The code did not meet any NYU/Billings category

  • injury (int) – Injury

  • drug (int) – Drug Related (excluding alcohol)

  • psych (int) – Mental Health Related

  • alcohol (int) – Alcohol Related

  • peds_acs_ed (int) – Pediatric ambuilatory care sensitive ED visit

  • ne (float) – Non-Emergent probability

  • epct (float) – Emergent, Primary Care Treatable probability

  • edcnpa (float) – Emergent, ED Care Needed, Preventable/Avoidable

  • edcnnpa (float) – Emergent, ED Care Needed, Not Preventable/Avoidable

Examples

>>> BillingsED.get_nyu_ed_categories('4659')
classmethod get_nyu_ed_proba_for_dx_code(dx_code: str) dict[source]

Merge with EDDXs gets the probbolities attached with the code

ed_category

description

nonemerg

Non-Emergent

emergpc

Emergent, Primary Care Treatable

emedpa

Emergent, ED Care Needed, Preventable/Avoidable

emednpa

Emergent, ED Care Needed, Not Preventable/Avoidable

Parameters:

dx_code (str) – Diagnosis code

Returns:

Dictionary with probability keys (‘nonemerg’, ‘emergpc’, ‘emedpa’, ‘emednpa’) and float values, or empty dict if the code is not found.

Return type:

dict

Examples

>>> BillingsED.get_nyu_ed_proba_for_dx_code('4659')
classmethod get_special_categories(dx_code: str) dict[source]

Categorizes the diagnosis code into below categories

category_code

description

injury

Injury

psych

Mental Health Related

alcohol

Alcohol Related

drug

Drug Related (excluding alcohol)

acs

Parameters:

dx_code (str) – Diagnosis code

Returns:

Dictionary with keys ‘acs’, ‘psych’, ‘drug’, ‘alcohol’, ‘injury’ and integer values (0 or 1).

Return type:

dict

Examples

>>> BillingsED.get_special_categories('E8600')
{'acs': 0, 'psych': 0, 'drug': 0, 'alcohol': 1, 'injury': 0}
classmethod is_peds_acsed(dx_code: str) int[source]

Checks if the diagnosis code meets pediatric ACS ED visit criteria

Parameters:

dx_code (str) – Diagnosis code

Returns:

1 if the code meets pediatric ACS ED criteria, 0 otherwise.

Return type:

int

Examples

>>> BillingsED.is_peds_acsed('493')
1
>>> BillingsED.is_peds_acsed('999')
0
logger_name = 'medicaid_utils.adapted_algorithms.py_nyu_billings.billings_ed'
lst_special_ed_categories = ['acs', 'psych', 'drug', 'alcohol', 'injury']
package_folder = '/home/runner/work/medicaid-utils/medicaid-utils/medicaid_utils/adapted_algorithms/py_nyu_billings'
pdf_nonstartswith_recode = origin target 10   78700   7870 10   78701   7870 10   78702   7870 10   78703   7870 11   78840   7884 ..     ...    ... 181   9694   9691 182   9985  99883 182  99859  99883 182  99889  99883 183   V589  V5889  [322 rows x 2 columns]
pdf_recode = origin target  ... deleted starts_with 0         [042, 043, 044]    042  ...       0           1 1                  [0781]   0781  ...       0           1 2                  [2501]   2501  ...       0           1 3                  [2780]   2780  ...       0           1 4                  [4151]   4151  ...       0           1 ..                    ...    ...  ...     ...         ... 179                [9592]   9593  ...       0           0 180          [9630, 9690]   9654  ...       0           0 181                [9694]   9691  ...       0           0 182  [9985, 99859, 99889]  99883  ...       0           0 183                [V589]  V5889  ...       0           0  [182 rows x 6 columns]
pdf_startswith_recode = origin target 0     042    042 0     043    042 0     044    042 1    0781   0781 2    2501   2501 3    2780   2780 4    4151   4151 5     493    493 6    5301   5301 7    5751   5751 8    6860   6860 9    7807   7807 12   7890   7890 13    850    850 14   8540    854 14   8541    854 15   9898   9898 16   9955   9955 17   9970   9970 19    v72    V72 19    V72    V72 62    682    682 62    684    682 62   6869    682
classmethod recode_diag_code(dx_code: str) str[source]

Recodes diagnosis code

Parameters:

dx_code (str) – Diagnosis code

Returns:

Recoded diagnosis code.

Return type:

str

Examples

>>> BillingsED.recode_diag_code('4659')
'4659'
medicaid_utils.adapted_algorithms.py_nyu_billings.billings_ed.get_nyu_ed_proba(df: DataFrame, date_col: str, index_col: str, cms_format: str = 'MAX') DataFrame[source]

This functions returns probabilities for dxgroup codes in the input dataframe being urgent, preventable, or optimally treated ED visits. This function recodes the passed dx codes to a set of dx codes used in (Billings, Parikh, and Mijanovich 2000b; Feldman 2010) study, adds columns (‘injury’, ‘psych’, ‘alcohol’ and ‘drug’), indicating the type of ED service.

Parameters:
  • df (dask.DataFrame) – dataframe with dx codes

  • date_col (str) – Date column name

  • index_col (str) – Index column name

  • cms_format ({'MAX', 'TAF'}) – CMS file format

Return type:

pd.DataFrame

Examples

>>> # Requires a dask DataFrame with ED claims and diagnosis columns
>>> pdf = get_nyu_ed_proba(df, 'srvc_bgn_date', 'MSIS_ID')