Last active
August 18, 2026 23:35
-
-
Save benjamin-chan/e5a49c2cfd2e2752a20282e7110d3d59 to your computer and use it in GitHub Desktop.
R function to query CMS Provider Data via API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getCMS <- function(datasetID = NULL, | |
| columns = "*", | |
| where = NULL, | |
| limit = 0, | |
| root = "https://data.cms.gov/provider-data/api/1/datastore/sql") | |
| { | |
| require(magrittr) | |
| require(httr) | |
| require(jsonlite) | |
| if (is.null(datasetID)) { | |
| message("\ndatasetID is null; here's a list of datasetIDs available:\n") | |
| url <- "https://data.cms.gov/provider-data/api/1/metastore/schemas/dataset/items" | |
| } | |
| else { | |
| url <- sprintf("https://data.cms.gov/provider-data/api/1/metastore/schemas/dataset/items/%s?show-reference-ids", datasetID) | |
| temp <- GET(url)$content %>% rawToChar() %>% fromJSON() | |
| distributionId <- temp[["distribution"]][["identifier"]] | |
| if (is.null(where)) { | |
| query <- sprintf("[SELECT %s FROM %s][LIMIT %d]", columns, distributionId, limit) | |
| } | |
| else { | |
| query <- sprintf("[SELECT %s FROM %s][WHERE %s][LIMIT %d]", columns, distributionId, where, limit) | |
| } | |
| options <- "show_db_columns=true" | |
| url <- sprintf("%s?query=%s&%s", root, query, options) %>% URLencode() | |
| } | |
| GET(url)$content %>% rawToChar() %>% fromJSON() | |
| } | |
| # EXAMPLES | |
| # getCMS() | |
| # dplyr::filter(getCMS() , theme == "Hospitals") %>% dplyr::select(theme, identifier, title, description) | |
| # getCMS("xubh-q36u", where = 'state = \"OR\"') # Hospital General Information | |
| # getCMS("ynj2-r877", where = 'facility_id = \"380009\"') # Complications and Deaths - Hospital |
benjamin-chan
commented
Aug 18, 2026
Author
| identifier | title | description | |
|---|---|---|---|
| 151 | 4a4e-e0da | Otolaryngology Office Visit Costs | Returns otolaryngology office visit costs per zip code for new and established patients. |
| 152 | wkfw-kthe | Outpatient Imaging Efficiency - Hospital | Use of medical imaging - provider data. These measures give you information about hospitals' use of medical imaging tests for outpatients. Examples of medical imaging tests include CT scans and MRIs. |
| 153 | di9i-zzrc | Outpatient Imaging Efficiency - National | Use of medical imaging - national data. These measures give you information about hospitals' use of medical imaging tests for outpatients. Examples of medical imaging tests include CT scans and MRIs. |
| 154 | if5v-4x48 | Outpatient Imaging Efficiency - State | Use of medical imaging - state data. These measures give you information about hospitals' use of medical imaging tests for outpatients. Examples of medical imaging tests include CT scans and MRIs. |
| 155 | 48nr-hqxx | Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey for ambulatory surgical centers - Facility | A list of ambulatory surgical center ratings for the Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey. The OAS CAHPS survey collects information about patients' experiences of care in hospital outpatient departments (HOPDs) and ambulatory surgical centers (ASCs). The data are updated and reported each quarter with data from the most recently completed quarter replacing the oldest quarter of data. |
| 156 | tf3h-mrrs | Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey for ambulatory surgical centers - National | The file contains the national average for the OAS CAHPS survey responses. The OAS CAHPS survey collects information about patients' experiences of care in hospital outpatient departments (HOPDs) and ambulatory surgical centers (ASCs). The data are updated and reported each quarter with data from the most recently completed quarter replacing the oldest quarter of data. |
| 157 | x663-bwbj | Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey for ambulatory surgical centers - State | A list of the state averages for the OAS CAHPS survey responses. The OAS CAHPS survey collects information about patients' experiences of care in hospital outpatient departments (HOPDs) and ambulatory surgical centers (ASCs). The data are updated and reported each quarter with data from the most recently completed quarter replacing the oldest quarter of data. |
| 158 | yizn-abxn | Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey for hospital outpatient departments - Facility | A list of hospital outpatient department ratings for the Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey. The OAS CAHPS survey collects information about patients' experiences of care in hospital outpatient departments (HOPDs) and ambulatory surgical centers (ASCs). The data are updated and reported each quarter with data from the most recently completed quarter replacing the oldest quarter of data. |
| 159 | s5pj-hua3 | Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey for hospital outpatient departments - National | The file contains the national average for the OAS CAHPS survey responses. The OAS CAHPS survey collects information about patients' experiences of care in hospital outpatient departments (HOPDs) and ambulatory surgical centers (ASCs). The data are updated and reported each quarter with data from the most recently completed quarter replacing the oldest quarter of data. |
| 160 | 6pfg-whmx | Outpatient and Ambulatory Surgery Consumer Assessment of Healthcare Providers and Systems (OAS CAHPS) survey for hospital outpatient departments - State | A list of the state averages for the OAS CAHPS Survey responses. The OAS CAHPS survey collects information about patients' experiences of care in hospital outpatient departments (HOPDs) and ambulatory surgical centers (ASCs). The data are updated and reported each quarter with data from the most recently completed quarter replacing the oldest quarter of data. |
| 161 | y2hd-n93e | Ownership | A list of ownership information for currently active nursing homes. |
| 162 | 7d6a-e7a6 | PY 2023 Clinician Public Reporting: MIPS Measures and Attestations | This file contains performance information for Merit-Based Incentive Payment System (MIPS) Quality, Promoting Interoperability, and Improvement Activities performance information submitted by clinicians. |
| 163 | a174-a962 | PY 2023 Clinician Public Reporting: Overall MIPS Performance | This file contains Merit-Based Incentive Payment System (MIPS) Final Scores and performance category scores for clinicians. For further details on 2023 MIPS scoring, see the 2023 Traditional MIPS Scoring Guide. |
| 164 | 0ba7-2cb0 | PY 2023 Group Public Reporting: MIPS Measures and Attestations | This file contains performance information for Merit-Based Incentive Payment System (MIPS) Quality, Promoting Interoperability, and Improvement Activities performance information submitted by groups. |
| 165 | 8c70-d353 | PY 2023 Group Public Reporting: Patient Experience | This file contains information for the Consumer Assessment of Healthcare Providers and Systems (CAHPS) for MIPS measures submitted by groups. |
| 166 | 46dc-a66c | PY 2023 Virtual Group Public Reporting: MIPS Measures and Attestations | This file contains performance information for Merit-Based Incentive Payment System (MIPS) Quality, Promoting Interoperability, and Improvement Activities performance information submitted by virtual groups. |
| 167 | cfa7-e909 | Pain Management Office Visit Costs | Returns pain management office visit costs per zip code for new and established patients. |
| 168 | qoeg-w7ck | Palliative Care - PPS-Exempt Cancer Hospital - Hospital | Palliative care is specialized medical care that focuses on providing relief from pain and other symptoms of a serious illness. These measures are first steps that seek to broadly assess what is happening in PCHs at the end-of-life and will provide a baseline picture of existing end-of-life care at these hospitals. |
| 169 | qigt-w5cx | Palliative Care - PPS-Exempt Cancer Hospital - National | Palliative care is specialized medical care that focuses on providing relief from pain and other symptoms of a serious illness. These measures are first steps that seek to broadly assess what is happening in PCHs at the end-of-life and will provide a baseline picture of existing end-of-life care at these hospitals. |
| 170 | 914a-7700 | Pathology Office Visit Costs | Returns pathology office visit costs per zip code for new and established patients. |
| 171 | 1su6-zfft | Patient Engagement PPS-Exempt Cancer Hospital - Hospital | This measure assesses goals of care discussion documentation among patients with cancer who die while receiving care at the reporting PCH. Goals of care discussions are discussions between patients with advanced cancer and the oncology team. These discussions can inform future treatment decisions that account for, and are responsive to, the interests expressed by patients. |
| 172 | 4dyz-5kt1 | Patient Engagement PPS-Exempt Cancer Hospital - National | This measure assesses goals of care discussion documentation among patients with cancer who die while receiving care at the reporting PCH. Goals of care discussions are discussions between patients with advanced cancer and the oncology team. These discussions can inform future treatment decisions that account for, and are responsive to, the interests expressed by patients. |
| 173 | iy27-wz37 | Patient Survey (PCH - HCAHPS) PPS-Exempt Cancer Hospital - Hospital | A list of hospital ratings for the Hospital Consumer Assessment of Healthcare Providers and Systems (HCAHPS). HCAHPS is a national, standardized survey of hospital patients about their experiences during a recent inpatient hospital stay. |
| 174 | 9g7e-btyt | Patient Survey (PCH - HCAHPS) PPS-Exempt Cancer Hospital - National | The national average for the HCAHPS survey categories. HCAHPS is a national, standardized survey of hospital patients about their experiences during a recent inpatient hospital stay. |
| 175 | qatj-nmws | Patient Survey (PCH - HCAHPS) PPS-Exempt Cancer Hospital - State | A list of the state averages for the HCAHPS survey responses. HCAHPS is a national, standardized survey of hospital patients about their experiences during a recent inpatient hospital stay. |
| 176 | dgck-syfz | Patient survey (HCAHPS) - Hospital | A list of hospital ratings for the Hospital Consumer Assessment of Healthcare Providers and Systems (HCAHPS). HCAHPS is a national, standardized survey of hospital patients about their experiences during a recent inpatient hospital stay. |
| 177 | 99ue-w85f | Patient survey (HCAHPS) - National | The national average for the HCAHPS survey categories. HCAHPS is a national, standardized survey of hospital patients about their experiences during a recent inpatient hospital stay. |
| 178 | 84jm-wiui | Patient survey (HCAHPS) - State | A list of the state averages for the HCAHPS survey responses. HCAHPS is a national, standardized survey of hospital patients about their experiences during a recent inpatient hospital stay. |
| 179 | 59mq-zhts | Patient survey (ICH CAHPS) - Facility | In-Center Hemodialysis Facilities Patient evaluations from the In-Center Hemodialysis Consumer Assessment of Healthcare Providers and Systems (ICH-CAHPS) Survey. The ICH-CAHPS Survey is a national, standardized survey of in-center hemodialysis patients about their experiences with the facility, facility doctors and staff, and care received. |
| 180 | utgq-v46w | Patient survey (ICH CAHPS) - National | The national average for ICH-CAHPS Survey measures. The ICH-CAHPS Survey is a national, standardized survey of in-center hemodialysis patients about their experiences with the facility, facility doctors and staff, and care received. |
| 181 | hanv-ru8h | Patient survey (ICH CAHPS) - State | State averages for ICH-CAHPS Survey measures. The ICH-CAHPS Survey is a national, standardized survey of in-center hemodialysis patients about their experiences with the facility, facility doctors and staff, and care received. |
| 182 | mxtu-43qs | Patient-Reported Outcomes - Hospital | Patient-reported outcomes are reports from patients about aspects of care that matter most to them, like pain management, functional ability (like their ability to walk, think, see, hear and remember), and overall quality of life. Through surveys or questionnaires, patients self-report the effectiveness of the care they got from their provider. |
| 183 | d226-80a4 | Pediatric Medicine Office Visit Costs | Returns pediatric medicine office visit costs per zip code for new and established patients. |
| 184 | g6vv-u9sr | Penalties | A list of the fines and payment denials received by nursing homes in the last three years. |
| 185 | ccbb-cbfa | Peripheral Vascular Disease Office Visit Costs | Returns peripheral vascular disease office visit costs per zip code for new and established patients. |
| 186 | 254e-694c | Pharmacy Office Visit Costs | Returns pharmacy office visit costs per zip code for new and established patients. |
| 187 | 5e3a-bee4 | Physical Medicine and Rehabilitation Office Visit Costs | Returns physical medicine and rehabilitation office visit costs per zip code for new and established patients. |
| 188 | 029b-dd7e | Physical Therapist in Private Practice Office Visit Costs | Returns physical therapist in private practice office visit costs per zip code for new and established patients. |
| 189 | 0d7d-e988 | Physician Assistant Office Visit Costs | Returns physician assistant office visit costs per zip code for new and established patients. |
| 190 | 32b2-9f88 | Plastic and Reconstructive Surgery Office Visit Costs | Returns plastic and reconstructive surgery office visit costs per zip code for new and established patients. |
| 191 | 8634-f6a7 | Podiatry Office Visit Costs | Returns podiatry office visit costs per zip code for new and established patients. |
| 192 | 0330-b6e0 | Preventive Medicine Office Visit Costs | Returns preventive medicine office visit costs per zip code for new and established patients. |
| 193 | f4ga-b9gx | Promoting Interoperability - Hospital | The Medicare Promoting Interoperability Program was developed to promote and prioritize interoperability and exchange of health care data. Promoting interoperability means that hospitals show they're using certified Electronic Health Record (EHR) technology in ways that can be measured against quality standards. |
| 194 | 4pq5-n9py | Provider Information | General information on currently active nursing homes, including number of certified beds, quality measure scores, staffing and other information used in the Five-Star Rating System. Data are presented as one row per nursing home. |
| 195 | 057a-5bcf | Psychiatry Office Visit Costs | Returns psychiatry office visit costs per zip code for new and established patients. |
| 196 | 92bb-de79 | Psychologist, Clinical Office Visit Costs | Returns psychologist, clinical office visit costs per zip code for new and established patients. |
| 197 | 2ca5-1007 | Public Health or Welfare Agency Office Visit Costs | Returns public health or welfare agency office visit costs per zip code for new and established patients. |
| 198 | 0127-af37 | Pulmonary Disease Office Visit Costs | Returns pulmonary disease office visit costs per zip code for new and established patients. |
| 199 | 288b-4bed | Radiation Oncology Office Visit Costs | Returns radiation oncology office visit costs per zip code for new and established patients. |
| 200 | 8283-8a65 | Registered Dietitian or Nutrition Professional Office Visit Costs | Returns registered dietitian or nutrition professional office visit costs per zip code for new and established patients. |
Author
| identifier | title | description | |
|---|---|---|---|
| 201 | 385c-8c97 | Rheumatology Office Visit Costs | Returns rheumatology office visit costs per zip code for new and established patients. |
| 202 | 7peb-i4pi | Rural Emergency Hospital Outpatient Imaging Efficiency - Hospital | This data set includes provider-level data for outpatient imaging efficiency quality measures included under the Rural Emergency Hospital Quality Reporting (REHQR) Program. |
| 203 | zt3q-3e1z | Rural Emergency Hospital Outpatient Imaging Efficiency - National | This data set includes national-level data for outpatient imaging efficiency quality measures included under the Rural Emergency Hospital Quality Reporting (REHQR) Program. |
| 204 | 97xg-v3wv | Rural Emergency Hospital Timely and Effective Care - Hospital | This data set includes provider-level data for timely and effective care (process of care) quality measures included under the Rural Emergency Hospital Quality Reporting (REHQR) Program. |
| 205 | d2k3-k3ac | Rural Emergency Hospital Timely and Effective Care - National | This data set includes national-level data for timely and effective care (process of care) quality measures included under the Rural Emergency Hospital Quality Reporting (REHQR) Program. |
| 206 | zez1-ka2w | Rural Emergency Hospital Unplanned Hospital Visits - Hospital | This data set includes provider-level data for unplanned hospital visits quality measures included under the Rural Emergency Hospital Quality Reporting (REHQR) Program. |
| 207 | uk3n-au7a | Rural Emergency Hospital Unplanned Hospital Visits - National | This data set includes national-level data for unplanned hospital visits quality measures included under the Rural Emergency Hospital Quality Reporting (REHQR) Program. |
| 208 | k653-4ka8 | Safety and Healthcare-Associated Infection Measures - PPS-Exempt Cancer Hospital | Prospective Payment System (PPS)-Exempt Cancer Hospital Quality Reporting (PCHQR) Program Healthcare Associated Infections. These measures are developed by Centers for Disease Control and Prevention (CDC) and collected through the National Healthcare Safety Network (NHSN). They provide information on infections that occur while the patient is in the hospital. These infections can be spread from patient to patient after contact with an infected person or surface. Many healthcare associated infections can be prevented when the hospitals use CDC-recommended infection control steps. |
| 209 | 5sqm-2qku | Skilled Nursing Facility Quality Reporting Program - National Data | Skilled Nursing Facilities (SNFs) provide Medicare Part A SNF services to beneficiaries and must report data on certain measures of quality to Medicare through the Skilled Nursing Facility Quality Reporting Program (SNF QRP). This file contains national averages on quality measures implemented under the IMPACT Act. |
| 210 | fykj-qjee | Skilled Nursing Facility Quality Reporting Program - Provider Data | Skilled Nursing Facilities (SNFs) provide Medicare Part A SNF services to beneficiaries and must report data on certain measures of quality to Medicare through the Skilled Nursing Facility Quality Reporting Program (SNF QRP). This file contains a list of SNFs, as well as their results on the quality of resident care measures implemented under the IMPACT Act. |
| 211 | 6uyb-waub | Skilled Nursing Facility Quality Reporting Program - Swing Beds - Provider Data | Non-Critical Access Hospitals (CAHs) with swing beds are hospitals that provide Medicare Part A Skilled Nursing Facility (SNF) services to beneficiaries and must report data on certain measures of quality to Medicare through the Skilled Nursing Facility Quality Reporting Program (SNF QRP). This file contains a list of the swing bed units participating in the SNF QRP, as well as their results on quality measures implemented under the IMPACT Act. |
| 212 | 39da-b8ab | Sleep Medicine Office Visit Costs | Returns sleep medicine office visit costs per zip code for new and established patients. |
| 213 | c713-00e8 | Sports Medicine Office Visit Costs | Returns sports medicine office visit costs per zip code for new and established patients. |
| 214 | xcdc-v8bm | State US Averages | A list of a variety of averages for each state or territory as well as the national average, including each quality measure, staffing, fine amount and number of deficiencies. Each row displays a specific state or territory, the associated measure and average. |
| 215 | hicp-9999 | State-Level Health Inspection Cut Points | State-specific ranges for the weighted health inspection score for each health inspection star rating category. Data are presented as one row per state or territory. |
| 216 | 0f6a-98c3 | Surgical Oncology Office Visit Costs | Returns surgical oncology office visit costs per zip code for new and established patients. |
| 217 | tbry-pc2d | Survey Summary | Nursing home summary information for nursing home health, fire safety, infection control, and complaint inspections in the last three years, including dates of the three most recent inspections (including those with no citations), and counts of citations, overall and within specified categories. Data are presented as one inspection per provider. Citation counts also include citations from infection control surveys and complaint inspections. |
| 218 | 5gv4-jwyv | Table 1: FY2024 Net Change in Base Operating DRG Payment Amount | Net Change in Base Operating DRG Payment Amount shows number of hospitals for specified ranges of value-based incentive payment amounts after subtracting the amount by which their Medicare payments per discharge were reduced. |
| 219 | xrgf-x36b | Table 2: FY2024 Distribution of Net Change in Base Operating DRG Payment Amount | Distribution of Net Change in Base Operating DRG Payment Amount shows the distribution of hospitals' value-based incentive payment amounts after subtracting the amount of the applicable percent reduction from their Medicare payments. |
| 220 | u625-zae7 | Table 3: FY2024 Percent Change in Medicare Payments | Percent Change in Medicare Payments displays how hospitals' Medicare payments changed as a result of the Hospital VBP Program in percentage terms. |
| 221 | vtqa-m4zn | Table 4: FY2024 Value-Based Incentive Payment Amount | Value-Based Incentive Payment Amount displays the number of hospitals that received value-based incentive payment amounts in ranges of $50,000. |
| 222 | 5d9c-1e86 | Thoracic Surgery Office Visit Costs | Returns thoracic surgery office visit costs per zip code for new and established patients. |
| 223 | yv7e-xc69 | Timely and Effective Care - Hospital | Timely and Effective Care measures - provider data. This data set includes provider-level data for measures of cataract surgery outcome, colonoscopy follow-up, emergency department care, preventive care, and pregnancy and delivery care. |
| 224 | isrn-hqyy | Timely and Effective Care - National | Timely and Effective Care measures - national data. This data set includes national-level data for measures of cataract surgery outcome, colonoscopy follow-up, emergency department care, preventive care, and pregnancy and delivery care. |
| 225 | apyc-v239 | Timely and Effective Care - State | Timely and Effective Care measures - state data. This data set includes state-level data for measures of cataract surgery outcome, colonoscopy follow-up, emergency department care, preventive care, and pregnancy and delivery care. |
| 226 | d1c9-d5b4 | Undefined Physician type Office Visit Costs | Returns undefined physician type office visit costs per zip code for new and established patients. |
| 227 | 993f-4504 | Undersea and Hyperbaric Medicine Office Visit Costs | Returns undersea and hyperbaric medicine office visit costs per zip code for new and established patients. |
| 228 | 632h-zaca | Unplanned Hospital Visits - Hospital | Unplanned Hospital Visits: provider data. This data set includes provider data for the hospital return days (or excess days in acute care [EDAC]) measures, the unplanned readmissions measures, and measures of unplanned hospital visits after outpatient procedures. |
| 229 | cvcs-xecj | Unplanned Hospital Visits - National | Unplanned Hospital Visits: national data. This data set includes national-level data for the hospital return days (or excess days in acute care [EDAC]) measures, the unplanned readmissions measures, and measures of unplanned hospital visits after outpatient procedures. |
| 230 | 4gkm-5ypv | Unplanned Hospital Visits - State | Unplanned Hospital Visits: state data. This data set includes state-level data for the hospital return days (or excess days in acute care [EDAC]) measures, the unplanned readmissions measures, and measures of unplanned hospital visits after outpatient procedures. |
| 231 | afcb-07d8 | Urology Office Visit Costs | Returns urology office visit costs per zip code for new and established patients. |
| 232 | n0yb-util | Utilization Data | The Doctors and Clinicians utilization data file reports volume information for procedures of interest on clinician profile pages and in the provider data catalog (PDC) to inform patients and caregivers about clinicians' experience. |
| 233 | f226-42b7 | Vascular Surgery Office Visit Costs | Returns vascular surgery office visit costs per zip code for new and established patients. |
| 234 | 6qxe-iqz8 | Veterans Health Administration Behavioral Health Data | A list of VHA hospitals with behavioral health measure data. VHA reports data on a set of core performance measures for Hospital-Based Inpatient Psychiatric Services (HBIPS), Substance Use, and Tobacco Treatment. |
| 235 | uyx4-5s7f | Veterans Health Administration Provider Level Data | A list of all VHA hospitals. The list includes addresses and phone numbers. |
| 236 | ptds-r8im | Veterans Health Administration Timely and Effective Care Data | A list of VHA hospitals with timely and effective care (process of care) measure data. VHA collects this information through a Quality Improvement Organization (External Peer Review Program) or directly from electronic medical records. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment