diff --git a/Project.toml b/Project.toml index d584166..a441bc4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "EHRAuthentication" uuid = "45047142-e73a-4b31-ae20-3729a1bbef33" authors = ["Dilum Aluthge", "Pumas-AI, Inc.", "contributors"] -version = "1.0.0" +version = "2.0.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/src/Cerner/system_accounts.jl b/src/Cerner/system_accounts.jl index 6b14b2d..3e970ea 100644 --- a/src/Cerner/system_accounts.jl +++ b/src/Cerner/system_accounts.jl @@ -1,7 +1,8 @@ Base.@kwdef struct CernerConfig base_url::String + grant_type::String = "client_credentials" headers::Dict{String, String} = Dict{String, String}() - scope::String = "grant_type=client_credentials&scope=system%2FObservation.read%20system%2FPatient.read" + scope::String # Example: scope = "system/Patient.read system/Observation.read" system_account_client_id::String system_account_client_secret::String end @@ -14,6 +15,7 @@ end function authenticate_fhir_cerner(config::CernerConfig) base_url = config.base_url + grant_type = config.grant_type headers = config.headers scope = config.scope system_account_client_id = config.system_account_client_id @@ -54,10 +56,14 @@ function authenticate_fhir_cerner(config::CernerConfig) for (k, v) in headers current_headers[k] = v end + body = string( + "grant_type=$(HTTP.escapeuri(grant_type))&", + "scope=$(HTTP.escapeuri(scope))&", + ) token_response = HTTP.request("POST", endpoints["token"], current_headers, - scope, + body, ) token_response_body = JSON3.read(String(token_response.body)) token_dict = copy(token_response_body)