MS-DRG
Column | Data Type | Description |
---|
Maintenance Instructions
CMS releases a list of MS-DRG codes twice a year effective April 1 and October 1. This list only contains valid codes and omits any that have been deprecated. Tuva maintains these deprecated code so historical data can be analyzed.
- Navigate to the CMS MS DRG website
- Under the section "MS-DRG Definitions Manual and Software", click on "V42 Definitions Manual Table of Contents - Full Titles - HTML Version"
- The version (e.g. V42) will change with each new release.
- Click on the hyperlink "Appendix A List of MS-DRGs Version 42.1"
- Click on the hyperlink "List of MS-DRGs Version 42.1"
- Copy and paste the list of MS-DRGs into any text editor and save it as a text file.
- Format the file
- Remove the text "MDC" from column 2
- Wrap the description in column 4 with double quotes so commas are interpreted correctly
Note: you can use the below script to format the file as said in number 6.
import pandas as pd
def main():
input_filename = "your text file path"
output_filename = "output csv file path"
with open(input_filename, 'r') as f:
lines = f.readlines()
rows = []
for line in lines:
line = line.strip()
if line: # ignore empty lines
parts = line.split(",", 3) # split only at the first 3 commas
rows.append(parts)
df = pd.DataFrame(rows, columns=["Code", "Group", "Type", "Description"])
print(df.head())
# Clean the Group column (remove 'MDC ' if exists)
df["Group"] = df["Group"].str.replace("MDC ", "", regex=False).str.strip()
df.to_csv(output_filename, index=False, header=True)
if __name__ == "__main__":
main()
- Save the file
- Import the csv file into any data warehouse that also has the previous version of MS-DRG loaded
- Use the SQL below to populate the
deprecated
anddeprecated_date
columns. The script does the following:- Compares the old file with the new file to determine if codes have been deprecated. If they have been, set the column "deprecated" to 1 and "deprecated_date" to the date the newest codes were published (i.e. the beginning of the current fiscal year)
- UNIONs the list of deprecated codes with new valid codes
- Cleans up any formatting issues with the output and creates a table.
-- create table from the output of the script
create table [ms_drg_new] as
-- compare the old codes with the new codes and only return codes that are missing
with depreacted_ms_drg_codes as(
select
old.ms_drg_code
, old.mdc_code
, old.medical_surgical
, old.ms_drg_description
, 1 as deprecated
, case when deprecated = 0 then '2023-10-01'
else deprecated_date
end as deprecated_date
from [previous_ms_drg_codes] old
left join [current_ms_drg_codes] new
on old.ms_drg_code = new.ms_drg_code
where new.ms_drg_code is null
)
-- union valid codes and depreacted codes together
, union_all_codes as(
select
ms_drg_code
, mdc_code
, medical_surgical
, 0 as deprecated
, null as deprecated_date
from [current_ms_drg_codes]
where ms_drg_code not in (select ms_drg_code from depreacted_ms_drg_codes)
union all
select
ms_drg_code
, mdc_code
, medical_surgical
, deprecated
, deprecated_date
from depreacted_ms_drg_codes
)
-- clean up formatting as necessary
select
trim(ms_drg_code) as ms_drg_code
, nullif(trim(mdc_code),'') as mdc_code
, trim(medical_surgical) as medical_surgical
, trim(ms_drg_description) as ms_drg_description
, trim(deprecated) as deprecated
, trim(deprecated_date) as deprecated_date
from union_all_codes
- Upload the newly created code list into S3 (credentials with write permissions to the S3 bucket are required)
-- example code for Snowflake
copy into s3://tuva-public-resources/terminology/ms_drg.csv
from [table_created_in_step_9]
file_format = (type = csv field_optionally_enclosed_by = '"')
storage_integration = [integration_with_s3_write_permissions]
OVERWRITE = TRUE;
- Create a branch in docs. Update the
last_updated
column with the current date (above). - Submit a pull request
The below steps are only required if the headers of the file need to be changed. The Tuva Project does not store the contents of the ms-drg file in GitHub.
- Create a branch in The Tuva Project
- Alter the headers as needed in MS-DRG file
- Submit a pull request