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

Show example use #2

Closed
vojtechhuser opened this issue Oct 27, 2017 · 8 comments
Closed

Show example use #2

vojtechhuser opened this issue Oct 27, 2017 · 8 comments

Comments

@vojtechhuser
Copy link

This is super cool project.

it would be nice to see this mimic the call like this one below
from http://docs.smarthealthit.org/

$ curl https://sb-fhir-dstu2.smarthealthit.org/api/smartdstu2/open/Patient/SMART-1551992
-H 'Accept: application/json'
{
"resourceType": "Patient",
"active": true,
"name": [{
"use": "official",
"family": ["Coleman"],
"given": ["Lisa","P."]
}],
"gender": "female",
"birthDate": "1948-04-14",
...
}

@slaverman
Copy link
Contributor

Hi, thank you for your input. See the code below how your search would look like with R on FHIR.

query <- c("active=true", "family=Coleman", "given=Lisa,P.", "gender=female", "birthDate=1948-04-14")
client$search("Patient", query)

We are still working on a proper README file with examples for the GitHub repo. The full documentation of R on FHIR is available on CRAN.

@vojtechhuser
Copy link
Author

thanks for reply

@gadepallivs
Copy link

Hi, do you have updated README ? The current example on github opens a blank page for auth. Is the CRAN release a stable one or the project is under active development ? Thank you

@slaverman
Copy link
Contributor

This version is stable, as well as the version on CRAN. Have you tried re-installing the httr package? Otherwise try with a different browser. For me it still works with httr v 1.4.0 and Firefox.

@gadepallivs
Copy link

may be I am missing something very basic here. This line of the code client <- fhirClient$new("https://vonk.fire.ly/") has only Endpoint, but no token or tokenUrl or authUrl. Do i need to download and setup the firly server on windows ? Below is what I did

library(RonFHIR)
#> Warning: package 'RonFHIR' was built under R version 3.5.3
library(httr)
#> Warning: package 'httr' was built under R version 3.5.3

# Setting up a fhirClient with OAuth 2.0
client <- fhirClient$new("https://vonk.fire.ly")
client
#> Endpoint: https://vonk.fire.ly/

client_id <- "id"
client_secret <- "secret"
app_name <- "TestApp"
scopes <- c("patient/*.read")

app <- httr::oauth_app(appname = app_name, client_id, client_secret)
oauth_endpoint <-
  httr::oauth_endpoint(
    authorize = paste(client$authUrl, "?aud=", client$endpoint, sep = ""),
    access = client$tokenUrl
  )
oauth_endpoint
#> <oauth_endpoint>
#>  authorize: ?aud=https://vonk.fire.ly/
# Below code opens a blank page --- 
# Waiting for authentication in browser...
# Press Esc/Ctrl + C to abort
# token <-
#   httr::oauth2.0_token(
#     endpoint = oauth_endpoint,
#     app = app,
#     scope = scopes
#   )

Created on 2019-03-19 by the reprex package (v0.2.1)

Session info
sessionInfo()
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 14393)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.1252 
#> [2] LC_CTYPE=English_United States.1252   
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] httr_1.4.0    RonFHIR_0.3.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.1      digest_0.6.18   R6_2.4.0        jsonlite_1.6   
#>  [5] magrittr_1.5    evaluate_0.13   highr_0.7       stringi_1.4.3  
#>  [9] curl_3.3        rmarkdown_1.12  tools_3.5.1     stringr_1.4.0  
#> [13] xfun_0.5        yaml_2.2.0      compiler_3.5.1  htmltools_0.3.6
#> [17] knitr_1.22

@slaverman
Copy link
Contributor

The endpoint https://vonk.fire.ly/ is an open endpoint and does not require authentication. You can try the SMART sandbox --> http://docs.smarthealthit.org/sandbox/

@gadepallivs
Copy link

Hi @slaverman . I tried with the SMART sandbox. https://r3.smarthealthit.org/. It says requires authorization and does the same thing.
RonFHIR works with SMART/FHIR ? If so, can you share an example for bulk query ?
Thank you

Press Esc/Ctrl + C to abort

Not sure, what I am missing. can you share

client <- fhirClient$new("https://r3.smarthealthit.org")
Warning: The endpoint requires authorization.

@slaverman
Copy link
Contributor

Bulk queries only work for Bulk data API's like https://bulk-data.smarthealthit.org/ or you can set up your own bulk server, see https://github.com/smart-on-fhir/bulk-data-server

If you have a Bulk data endpoint, you can use the snippet below.

privatekey <- openssl::read_key("PrivateKey.pem")

# Create your claim
claim <- jose::jwt_claim(iss = "ServiceURL",
                         sub = "ClientID",
                         aud = "TokenURL",
			 # expiration date as epoch (5 minutes)
                         exp = as.integer(as.POSIXct( Sys.time() + 300)), 
   			 # 'random' number
                         jti = charToRaw(as.character(runif(1, 0.5, 100000000000)))) 

# Sign your claim with your private key
jwt <- jose::jwt_encode_sig(claim, privatekey)

# Define your scope(s)
scopes <- c("system/*.read", "system/CommunicationRequest.write")

# Create a new fhirBulkClient
bulkclient <- fhirBulkClient$new("FHIRBulkServerURL", tokenURL = "TokenURL")

# Retrieve your token
token <- bulkclient$retrieveToken(jwt, scopes)

# Set your token
bulkclient$setToken(token$access_token)

# Request a download for Patient Cohort 3
bulkclient$groupExport(3)

# Request the progress of the requests
bulkclient$getBulkStatus()

# When the downloads a available, download the bulkdata
patient_cohort_3 <- bulkclient$downloadBulk(1)

View(patient_cohort_3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants