Docley / app / tools / refresh.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Downloads the newest official files and reloads Docley's D1 database. |
| 3 | # NPPES full file (CMS): https://download.cms.gov/nppes/NPI_Files.html |
| 4 | # NUCC taxonomy names: https://www.nucc.org (Provider Taxonomy, CSV) |
| 5 | # HHS-OIG LEIE exclusions: https://oig.hhs.gov/exclusions/exclusions_list.asp |
| 6 | # Usage: tools/refresh.sh [work dir, default /Volumes/Expand/Projects/Docley/data] [--remote|--local] |
| 7 | set -euo pipefail |
| 8 | cd "$(dirname "$0")/.." |
| 9 | work="${1:-/Volumes/Expand/Projects/Docley/data}"; where="${2:---remote}" |
| 10 | mkdir -p "$work"; cd_repo="$PWD" |
| 11 | ua="Mozilla/5.0 (Docley data refresh)" |
| 12 | |
| 13 | nppes_url=$(curl -fsSL -A "$ua" https://download.cms.gov/nppes/NPI_Files.html | grep -oE 'https?://download\.cms\.gov/nppes/NPPES_Data_Dissemination_[A-Za-z]+_[0-9]{4}(_V2)?\.zip' | head -1) |
| 14 | [ -n "$nppes_url" ] || nppes_url="https://download.cms.gov/nppes/$(curl -fsSL -A "$ua" https://download.cms.gov/nppes/NPI_Files.html | grep -oE 'NPPES_Data_Dissemination_[A-Za-z]+_[0-9]{4}(_V2)?\.zip' | head -1)" |
| 15 | echo "NPPES: $nppes_url" |
| 16 | zip="$work/$(basename "$nppes_url")" |
| 17 | [ -f "$zip" ] || curl -fL -A "$ua" -o "$zip" "$nppes_url" |
| 18 | csv=$(unzip -Z1 "$zip" | grep -E '^npidata_pfile_[0-9-]+\.csv$' | head -1) |
| 19 | [ -f "$work/$csv" ] || unzip -o "$zip" "$csv" -d "$work" |
| 20 | |
| 21 | nucc_page=$(curl -fsSL -A "$ua" "https://www.nucc.org/index.php/code-sets-mainmenu-41/provider-taxonomy-mainmenu-40/csv-mainmenu-57") |
| 22 | nucc_path=$(echo "$nucc_page" | grep -oE '/images/stories/CSV/nucc_taxonomy_[0-9]+\.csv' | head -1) |
| 23 | curl -fsSL -A "$ua" -o "$work/nucc.csv" "https://www.nucc.org$nucc_path" |
| 24 | curl -fsSL -A "$ua" -o "$work/leie.csv" "https://oig.hhs.gov/exclusions/downloadables/UPDATED.csv" |
| 25 | |
| 26 | rm -rf "$work/sql" |
| 27 | node tools/import-nppes.mjs --nppes "$work/$csv" --nucc "$work/nucc.csv" --out "$work/sql" |
| 28 | node tools/import-leie.mjs --leie "$work/leie.csv" --out "$work/sql" |
| 29 | tools/load-d1.sh "$work/sql" "$where" |
| 30 | echo "Docley data refreshed from $nppes_url" |