BridgeClient::API

BridgeClient::API contains methods that wrap each endpoint of the Platform API directly.

Note: All methods described will raise a RestClient::ExceptionWithResponse if the Platform API has any issues with the request.

self.select

self.select(select, parameters = [])

Class method that is a wrapper around the "query/select" Platform API endpoint

Parameters

Name Description
select Select sql statement string, with parameters replaced with $1, $2, etc
parameters Parameters used in sql statement string, to replace $1, $2, etc. Optional.

Returns

{
  "results": Array of returned rows,
  "count": Number of rows
}

Example

BridgeClient::API.select(
  "SELECT .procedures.code, accession FROM rad_exams re WHERE re.id = $1 AND .procedures.code = $2"),
  [1234, "proc-code-4"]
)

=> {
  "results": [
    {
      "procedures_code": "proc-code-4",
      "accession": "ACC1234"
    }
  ],
  "count": 1
}

self.insert

self.insert(insert, parameters = [])

Class method that is a wrapper around the "query/insert" Platform API endpoint

Parameters

Name Description
insert Insert sql statement string, with parameters replaced with $1, $2, etc
parameters Parameters used in sql statement string, to replace $1, $2, etc. Optional.

Returns

{
  "results": Array of returned rows, contains only the row you inserted,
  "count": Number of rows (always 1)
}

Example

BridgeClient::API.insert(
  "INSERT INTO my_app_schema.my_table_name (col1, col2) VALUES ($1, $2)",
  [
    "some value for column 1",
    "some value for column 2"
  ]
)

=> {
  "results": [
    {
      "col1": "some value for column 1",
      "col2": "some value for column 2"
    }
  ],
  "count": 1
}

self.update

self.update(update, parameters = [])

Class method that is a wrapper around the "query/update" Platform API endpoint

Parameters

Name Description
update Update sql statement string, with parameters replaced with $1, $2, etc
parameters Parameters used in sql statement string, to replace $1, $2, etc. Optional.

Returns

{
  "results": Array of returned rows, contains only the rows you updated,
  "count": Number of rows updated
}

Example

BridgeClient::API.update(
  "UPDATE my_app_schema.my_table_name set col1 = $1, col2 = $2 WHERE id = $3",
  [
    "some value for column 1",
    "some value for column 2",
    1
  ]
)

=> {
  "results": [
    {
      "col1": "some value for column 1",
      "col2": "some value for column 2"
    }
  ],
  "count": 1
}

self.delete

self.delete(delete, parameters = [])

Class method that is a wrapper around the "query/delete" Platform API endpoint

Parameters

Name Description
delete Delete sql statement string, with parameters replaced with $1, $2, etc
parameters Parameters used in sql statement string, to replace $1, $2, etc. Optional.

Returns

{
  "results": Array of returned rows, contains only the row you deleted,
  "count": Number of rows (always 1)
}

Example

BridgeClient::API.delete(
  "DELETE FROM my_app_schema.my_table_name WHERE id = $1",
  [1]
)

=> {
  "results": [
    {
      "procedures_code": "proc-code-4",
      "accession": "ACC1234"
    }
  ],
  "count": 1
}

self.valid_token

self.valid_token(token, destination = '')

Class method that is a wrapper around the "user/valid_token" Platform API endpoint. Given a token, check if it is valid against single sign-on. Token validity is analogous to being logged in successfully. When a token is not valid a redirect location is specified whereby the user can log in. The redirect URL will place the user into the OIDC code flow.

Parameters

Name Description
token Token as a string that is being verified whether still valid or not.
destination Destination url as a string. The returned hash will contain a redirect property based on the destination that was provided. For example, the returned redirect url may be http://login.page?destination=http://where.i.want.to.go.after.logging.in Optional.

Returns

{
  "authenticate": Boolean, true or false depending on whether the user is authenticated or not,
  "username": Username as a string, including the domain,
  "redirect": URL for where the user should go in order to authenticate, as a string,
  "employee_id": Employee ID as a number
}

Example

BridgeClient::API.validate_token(
  "long sso token",
  "http://where.i.want.to.go.after.logging.in"
)

=> {
  "authenticate": true,
  "username": "domain1/attendingbob1",
  "redirect": "http://login.page?destination=http://where.i.want.to.go.after.logging.in",
  "employee_id": 2
}

self.authorize

self.authorize(username_or_id, roles)

Class method that is a wrapper around the "user/authorize" Platform API endpoint. Given a username or id and roles, check if the user is authorized for the given roles.

Parameters

Name Description
username_or_id Username as a string or employee ID as a number
roles Either an array of string roles, or a hash with and or or as keys and arrays as values. [“role1”,“role2"] is treated as an or. {“and” => [“role1",“role2”]} is treated as an and. {“or” => [“role1",“role2”]} is treated as an or.

Returns

User is authorized

{
  "employee_id" => Employee ID,
  "authorize" => true
}

User is not authorized

{
  "authorize "=> false
}

Example

BridgeClient::API.authorize(
  2,
  "roles": {
    "and": [
      "radiologist",
      "administrator"
    ]
  }
)

=> {
  "employee_id" => 1,
  "authorize" => true
}

self.validate_and_authorize

self.validate_and_authorize(token, roles, destination = '')

Class method that is a wrapper around the "user/validate_and_authorize" Platform API endpoint. Given a token and roles check if the token is valid and if the user is authorized based on the given roles. This begins with the same logic as /user/validate_token (an OIDC code flow) and then performs role based authorization checks.

Parameters

Name Description
token Token as a string that is being verified whether still valid or not.
roles Either an array of string roles, or a hash with and or or as keys and arrays as values. [“role1”,“role2"] is treated as an or. {“and” => [“role1",“role2”]} is treated as an and. {“or” => [“role1",“role2”]} is treated as an or.
destination Destination url as a string. The returned hash will contain a redirect property based on the destination that was provided. For example, the returned redirect url may be http://login.page?destination=http://where.i.want.to.go.after.logging.in Optional.

Returns

{
  "authenticate": Boolean, whether the user is authenticated based on the token,
  "authorize": Boolean, whether the user is authorized based on the token and roles,
  "username": Username as string,
  "redirect": URL for where the user should go in order to authenticate, as a string,
}

Example

BridgeClient::API.validate_and_authorize(
  "long sso token",
  "roles": {
    "and": [
      "radiologist",
      "administrator"
    ]
  },
  "http://where.i.want.to.go.after.logging.in"
}
)

=> {
  "authenticate": true,
  "authorize": true,
  "username": "domain1/attendingbob1",
  "redirect": "http://login.page?destination=http://where.i.want.to.go.after.logging.in"
}

self.hipaa_log

self.hipaa_log(request_info, requesting_ip, user_login, user_domain, table_name, ids)

Class method that is a wrapper around the "hipaa/audit" Platform API endpoint. Specify a list of record ids to log to the hipaa audit.

Parameters

Name Description
request_info Request info
requesting_ip Requesting IP address
user_login Username
user_domain Domain
table_name Table that the data being HIPAA logged belongs to (ex: rad_exams or orders or employees)
ids IDs of the rows in the table_name of the data needing to be logged

Returns

{
  "ok": true
}

Example

BridgeClient::API.hipaa_log(
  "http://domain.com/service-tools/view?exam=1",
  "127.0.0.1",
  "ldapusername",
  "realm",
  "rad_exams",
  [1, 2, 3]
)

=> {
  "ok": true
}

self.log_usage_data

self.log_usage_data(params)

Class method that is a wrapper around the "usage" Platform API endpoint. Publish app usage data to messaging bus.

Parameters

Name Description
params Hash of parameters that you want to log. Required keys are :ip, :url, :relative_url, and :application_name

Returns

{
  "ok": true
}

Example

BridgeClient::API.log_usage_data({
  "request_info": "http://domain.com/service-tools/view?exam=1",
  "requesting_ip": "127.0.0.1",
  "user_login": "ldapusername",
  "user_domain": "realm",
  "table_name": "rad_exams",
  "ids": [1, 2, 3]
})

=> {
  "ok": true
}