#!/usr/bin/env bash # Downloads the newest official files and reloads Docley's D1 database. # NPPES full file (CMS): https://download.cms.gov/nppes/NPI_Files.html # NUCC taxonomy names: https://www.nucc.org (Provider Taxonomy, CSV) # HHS-OIG LEIE exclusions: https://oig.hhs.gov/exclusions/exclusions_list.asp # Usage: tools/refresh.sh [work dir, default /Volumes/Expand/Projects/Docley/data] [--remote|--local] set -euo pipefail cd "$(dirname "$0")/.." work="${1:-/Volumes/Expand/Projects/Docley/data}"; where="${2:---remote}" mkdir -p "$work"; cd_repo="$PWD" ua="Mozilla/5.0 (Docley data refresh)" 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) [ -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)" echo "NPPES: $nppes_url" zip="$work/$(basename "$nppes_url")" [ -f "$zip" ] || curl -fL -A "$ua" -o "$zip" "$nppes_url" csv=$(unzip -Z1 "$zip" | grep -E '^npidata_pfile_[0-9-]+\.csv$' | head -1) [ -f "$work/$csv" ] || unzip -o "$zip" "$csv" -d "$work" nucc_page=$(curl -fsSL -A "$ua" "https://www.nucc.org/index.php/code-sets-mainmenu-41/provider-taxonomy-mainmenu-40/csv-mainmenu-57") nucc_path=$(echo "$nucc_page" | grep -oE '/images/stories/CSV/nucc_taxonomy_[0-9]+\.csv' | head -1) curl -fsSL -A "$ua" -o "$work/nucc.csv" "https://www.nucc.org$nucc_path" curl -fsSL -A "$ua" -o "$work/leie.csv" "https://oig.hhs.gov/exclusions/downloadables/UPDATED.csv" rm -rf "$work/sql" node tools/import-nppes.mjs --nppes "$work/$csv" --nucc "$work/nucc.csv" --out "$work/sql" node tools/import-leie.mjs --leie "$work/leie.csv" --out "$work/sql" tools/load-d1.sh "$work/sql" "$where" echo "Docley data refreshed from $nppes_url"