Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LANTERN-593: Added logging for the automatic populatedb prod cron job #398

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions scripts/automatic_populatedb_prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ EMAIL=

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
log_file="/etc/lantern/logs/automatic_populatedb_prod_logs.txt"
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")

#update source data from endpoint source list and NPPES
cd ../resources/prod_resources
Expand All @@ -24,29 +26,33 @@ PASTNPPESFILE="https://download.cms.gov/nppes/NPPES_Data_Dissemination_${PASTMON
rm -f endpoint_pfile.csv
rm -f npidata_pfile.csv

echo "Downloading ${MONTH} NPPES Resources..."
curl -s -f -o temp.zip ${NPPESFILE} || echo "${MONTH} NPPES Resources not available, downloading ${PASTMONTH} NPPES Resources..." && curl -s -o temp.zip ${PASTNPPESFILE}
echo "Extracting endpoint and npidata files from NPPES zip file..."
echo "$current_datetime - Downloading ${MONTH} NPPES Resources..." >> $log_file
curl -s -f -o temp.zip ${NPPESFILE} || {
echo "$current_datetime - ${MONTH} NPPES Resources not available, downloading ${PASTMONTH} NPPES Resources..." >> $log_file && curl -s -o temp.zip ${PASTNPPESFILE}
}
echo "$current_datetime - Extracting endpoint and npidata files from NPPES zip file..." >> $log_file
unzip -q temp.zip endpoint_pfile\*.csv
unzip -q temp.zip npidata_pfile\*.csv
rm *fileheader.csv
mv endpoint_pfile*.csv endpoint_pfile.csv
mv npidata_pfile*.csv npidata_pfile.csv
rm temp.zip

echo "Removing all entries from npidata_pfile that are not Entity Type 2 (Organization)..."
echo "$current_datetime - Removing all entries from npidata_pfile that are not Entity Type 2 (Organization)..." >> $log_file
sed -E '/^[^,]*,[^,]*(\"1\"|\"\")/d' npidata_pfile.csv > npidata_pfile2.csv
rm npidata_pfile.csv
mv npidata_pfile2.csv npidata_pfile.csv

echo "Populating db with endpoint and NPPES information..."
echo "$current_datetime - Populating db with endpoint and NPPES information..." >> $log_file
cd ../../scripts
docker exec lantern-back-end_endpoint_manager_1 /etc/lantern/populatedb.sh || echo "Lantern failed to save endpoint information in database and download and save NPPES information." | /usr/bin/mail -s "Automatic prod database population error." ${EMAIL}

docker exec lantern-back-end_endpoint_manager_1 /etc/lantern/populatedb.sh || {
echo "$current_datetime - Lantern failed to save endpoint information in database and download and save NPPES information." >> $log_file
echo "Lantern failed to save endpoint information in database and download and save NPPES information." | /usr/bin/mail -s "Automatic prod database population error." ${EMAIL}
}
cd ../resources/prod_resources
rm -f endpoint_pfile.csv
rm -f endpoint_pfile
rm -f npidata_pfile.csv
rm -f npidata_pfile

echo "done"
echo "$current_datetime - done" >> $log_file
Loading