From c4285b149ee1088ee9adaf7c2be479d6b3b30ccd Mon Sep 17 00:00:00 2001 From: Prasad Konka Date: Tue, 5 Sep 2023 03:19:52 -0400 Subject: [PATCH] Update REST api to read daily cached file --- api/download/downloadsmodule.R | 4 +++- api/download/restendpoints.R | 12 +++++++++--- docker-compose.override.yml | 3 +++ scripts/save_daily_csv_export.sh | 7 ++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/api/download/downloadsmodule.R b/api/download/downloadsmodule.R index ce23a6dc3..ff8522940 100644 --- a/api/download/downloadsmodule.R +++ b/api/download/downloadsmodule.R @@ -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, "")) %>% @@ -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 } diff --git a/api/download/restendpoints.R b/api/download/restendpoints.R index 095a2bea4..4b1b1fa2b 100644 --- a/api/download/restendpoints.R +++ b/api/download/restendpoints.R @@ -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") } \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 4a8dd51eb..51d265eb2 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -43,3 +43,6 @@ services: ports: - "3838:3838" + plumber: + ports: + - "8989:8989" \ No newline at end of file diff --git a/scripts/save_daily_csv_export.sh b/scripts/save_daily_csv_export.sh index 170698725..6424a7a0e 100644 --- a/scripts/save_daily_csv_export.sh +++ b/scripts/save_daily_csv_export.sh @@ -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 \ No newline at end of file