Skip to content

Commit

Permalink
Update REST api to read daily cached file
Browse files Browse the repository at this point in the history
  • Loading branch information
svginc committed Sep 5, 2023
1 parent 0130fd3 commit c4285b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion api/download/downloadsmodule.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ get_endpoint_organizations <- function(db_connection) {
get_endpoint_export_tbl <- function(db_tables) {

endpoint_organization_tbl <- get_endpoint_organizations(db_connection)

print(endpoint_organization_tbl)
endpoint_export_tbl <- db_tables$endpoint_export %>%
collect() %>%
mutate(vendor_name = na_if(vendor_name, "")) %>%
Expand All @@ -28,6 +28,8 @@ endpoint_export_tbl <- db_tables$endpoint_export %>%
mutate(endpoint_names = gsub("NULL", "", as.character(endpoint_names))) %>%
mutate(endpoint_names = gsub("(\")", "", as.character(endpoint_names))) %>%
mutate(format = gsub("(\"|\"|\\[|\\])", "", as.character(format)))
print("endpoint_export_tbl")
print(endpoint_export_tbl)
endpoint_export_tbl
}

Expand Down
12 changes: 9 additions & 3 deletions api/download/restendpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ source("downloadsmodule.R")

#* @apiTitle Download Daily FHIR Endpoints report
#* Echo Download Daily FHIR Endpoints report
#* @get /api/download
#* @get /daily/download
function(res) {
res$setHeader("Content-Type", "text/csv")
res$setHeader("Content-Disposition", "attachment; filename=fhir_endpoints.csv")
write.csv(get_fhir_endpoints_tbl(db_tables), file='fhir_endpoints.csv', row.names=FALSE)
include_file('fhir_endpoints.csv', res, content_type = "text/csv")
st <- format(Sys.time(), "%Y-%m-%d")
filename <- paste("fhir_endpoints_", st, ".csv", sep = "")
print(filename)
if (!file.exists(filename)) {
print("Not")
write.csv(get_fhir_endpoints_tbl(db_tables), file=filename, row.names=FALSE)
}
include_file(filename, res, content_type = "text/csv")
}
3 changes: 3 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ services:
ports:
- "3838:3838"

plumber:
ports:
- "8989:8989"
7 changes: 4 additions & 3 deletions scripts/save_daily_csv_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ mkdir -p $FILE_DIR

EXPORTFILE="/etc/lantern/dailyexport/$FILE_NAME"
echo $EXPORTFILE
URL="http://127.0.0.1:8989/api/download"
#URL="http://127.0.0.1:8989/api/download"
URL="https://lantern.healthit.gov/api/daily/download"
curl -o "$EXPORTFILE" "$URL"
mv "$EXPORTFILE" "$FILE_DIR/$FILE_NAME"

cd $FILE_DIR

git pull
git checkout daily_export
git checkout main
git add $FILE_NAME
git commit -m "Adding daily export file ${FILE_NAME}"
git push --set-upstream origin daily_export
git push --set-upstream origin main

0 comments on commit c4285b1

Please sign in to comment.