Skip to content

Commit

Permalink
Merge branch 'master' into version1
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Goodman committed Nov 1, 2013
2 parents 30f1e23 + 19d61c8 commit e565b10
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 35 deletions.
154 changes: 130 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,46 @@ Or install it yourself as:

### Creating clients

The Allscripts Unity API has three endpoints: GetSecurityToken, Magic, and RetireSecurityToken and supports both SOAP and JSON.
A Unity API client can be created using the `AllscriptsUnityClient#create` factory:
The Allscripts Unity API supports both JSON and SOAP. Both versions are supported by this gem.
A Unity API client can be created using the `AllscriptsUnityClient.create` factory:

```ruby
unity_client = AllscriptsUnityClient.create(:base_unity_url => "http://unity.base.url", :appname => "appname", :username => "username", :password => "password")
unity_client = AllscriptsUnityClient.create({
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password"
})
```

A JSON client can also be created using the `:mode` option:

```ruby
# Mode defaults to :soap
unity_client = AllscriptsUnityClient.create(:mode => :json, :base_unity_url => "http://unity.base.url", :appname => "appname", :username => "username", :password => "password")
unity_client = AllscriptsUnityClient.create({
:mode => :json,
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password"
})
```

### Security token management

The `create` factory will request a security token from Unity when created. The token can be accessed using the `security_token` accessor:
Security tokens can be manually requested using the `get_security_token!` method:

```ruby
unity_client.security_token
unity_client.get_security_token! # Fetches a new security token and stores it in security_token
```

Existence of a security token can also be checked:

```ruby
unity_client.security_token?
```
After calling `get_security_token!`, each call to `magic` will automatically send `security_token` with the request. If a security token is
no longer valid, an exception will be raised by Unity.

Security tokens can be manually requested using the `get_security_token!` method:
The token can be accessed using the `security_token` accessor:

```ruby
unity_client.get_security_token! # Fetches a new security token and stores it in security_token
unity_client.security_token
```

Security tokens can be retired using the `retire_security_token!` method:
Expand All @@ -60,8 +68,11 @@ Security tokens can be retired using the `retire_security_token!` method:
unity_client.retire_security_token! # Retires the security token with Unity and sets security_token to nil
```

After calling `get_security_token!`, each call to `magic` will automatically send `security_token` with the request. If a security token is
no longer valid, an exception will be raised by Unity.
Existence of a security token can also be checked:

```ruby
unity_client.security_token?
```

### Executing Magic calls

Expand Down Expand Up @@ -113,34 +124,129 @@ A number of helper methods exist that abstract away the details of the Magic ope

All magic helper methods not on this list currently raise `NotImplementedError`. More helper methods will be added in future releases. Pull requests welcome.

## Timezone
### Timezone

All times and dates coming from Unity are in local timezones. When creating the client, the `:timezone` option can be used to configure
automatic timezone conversion. If no `:timezone` is given, then it will default to `UTC`. Timezones must be given in `TZInfo` zone identifier
format. See [TZInfo](http://tzinfo.github.io/) for more information:

```ruby
unity_client = AllscriptsUnityClient.create(:timezone => "America/New_York", :base_unity_url => "http://unity.base.url", :appname => "appname", :username => "username", :password => "password")
unity_client = AllscriptsUnityClient.create({
:timezone => "America/New_York",
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password"
})
```

Any `magic` action that takes in a date needs to be given in UTC. Dates can be `Date`, `DateTime`, `Time`, or a string. Dates will be processed and formatted in the correct
[ISO8601](http://en.wikipedia.org/wiki/ISO_8601) format that Unity requires.

## Logging
### Logging

By default Ruby's `Logger` is used and logs to `STDOUT` with a level of `Logger::INFO`. Custom loggers can be configured with the `:logger` option:

```ruby
unity_client = AllscriptsUnityClient.create({
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password",
:logger => Rails.logger
})
```

Logging can also be disabled with the `:log` option:

```ruby
unity_client = AllscriptsUnityClient.create({
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password",
:log => false
})
```

Responses are not logged and Magic action is the only parameter logged with requests. This is done to prevent exposing PHI.

By default Ruby's Logger is used and logs to STDOUT with level Logger::INFO. Custom loggers can be configured:
### Proxy

An HTTP proxy can be configured using the `:proxy` option:

```ruby
unity_client = AllscriptsUnityClient.create(:base_unity_url => "http://unity.base.url", :appname => "appname", :username => "username", :password => "password", :logger => Rails.logger)
unity_client = AllscriptsUnityClient.create({
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password",
:proxy => "http://localhost:8888"
})
```

Logging can also be disabled:
## Examples

### GetServerInfo SOAP

```ruby
unity_client = AllscriptsUnityClient.create(:base_unity_url => "http://unity.base.url", :appname => "appname", :username => "username", :password => "password", :log => false)
unity_client = AllscriptsUnityClient.create({
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password",
:timezone => "America/New_York"
})

unity_client.get_security_token!

# API call made using a helper
unity_client.get_server_info
```

Magic action is the only parameter logged with requests and responses are not logged. This is done to prevent logging PHI.
The above example would output the following `Hash`:

```
{
:server_time_zone => "Eastern Standard Time",
:server_time => #<DateTime: 2013-11-01T15:49:23+00:00 ((2456598j,56963s,0n),+0s,2299161j)>,
:server_date_time_offset => #<DateTime: 2013-11-01T19:49:23+00:00 ((2456598j,71363s,0n),+0s,2299161j)>,
:system => "Enterprise EHR",
:product_version => "11.2.3.32.000",
:uaibornondate => #<Date: 2013-07-10 ((2456484j,0s,0n),+0s,2299161j)>
}
```

### GetServerInfo JSON

```ruby
unity_client = AllscriptsUnityClient.create({
:mode => :json
:base_unity_url => "http://unity.base.url",
:appname => "appname",
:username => "username",
:password => "password",
:timezone => "America/New_York"
})

unity_client.get_security_token!

# API call made using a helper
unity_client.get_server_info
```

The above example would output the following `Hash`:

```
{
:server_time_zone => "Eastern Standard Time",
:server_time => #<DateTime: 2013-11-01T15:49:23+00:00 ((2456598j,56963s,0n),+0s,2299161j)>,
:server_date_time_offset => #<DateTime: 2013-11-01T19:49:23+00:00 ((2456598j,71363s,0n),+0s,2299161j)>,
:system => "Enterprise EHR",
:product_version => "11.2.3.32.000",
:uaibornondate => #<Date: 2013-07-10 ((2456484j,0s,0n),+0s,2299161j)>
}
```

## Contributing

Expand All @@ -154,7 +260,7 @@ Magic action is the only parameter logged with requests and responses are not lo

Maintainer(s): Ash Gupta (https://github.com/incomethax), Neil Goodman (https://github.com/posco2k8)

## License:
## License

Copyright (c) 2013 healthfinch, Inc

Expand Down
3 changes: 2 additions & 1 deletion allscripts_unity_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "net-http-persistent", "~> 2.9.0"
gem.add_runtime_dependency "tzinfo", "~> 0.3.29"
gem.add_runtime_dependency "tzinfo-data", "~> 1.2013.7"
gem.add_runtime_dependency "nokogiri", "~> 1.5.0"
gem.add_runtime_dependency "nokogiri", "< 1.6", ">= 1.4.0"
gem.add_runtime_dependency "nori", "~> 2.3.0"

gem.add_development_dependency "factory_girl", "~> 4.2.0"
gem.add_development_dependency "rake", "~> 10.1.0"
Expand Down
1 change: 0 additions & 1 deletion lib/allscripts_unity_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def self.create(parameters = {})
end

client = Client.new(client_driver)
client.get_security_token!
client
end

Expand Down
1 change: 1 addition & 0 deletions lib/allscripts_unity_client/utilities.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "nori"
require "date"

module AllscriptsUnityClient
Expand Down
2 changes: 1 addition & 1 deletion lib/allscripts_unity_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AllscriptsUnityClient
VERSION = "1.0.3"
VERSION = "1.0.4"
end
8 changes: 0 additions & 8 deletions spec/allscripts_unity_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,23 @@

subject { AllscriptsUnityClient }

let(:get_security_token) { FixtureLoader.load_file("get_security_token.xml") }

before(:all) { savon.mock! }
after(:all) { savon.unmock! }

describe '.create' do
context 'when given :mode => :soap' do
it 'returns a SOAPClient' do
savon.expects("GetSecurityToken").with(:message => :any).returns(get_security_token)
parameters = FactoryGirl.build(:allscripts_unity_client_parameters, :mode => :soap)
expect(subject.create(parameters).client_type).to be(:soap)
end
end

context 'when given :mode => :json' do
it 'returns a client with client_type :json' do
stub_request(:post, "http://www.example.com/Unity/UnityService.svc/json/GetToken")
parameters = FactoryGirl.build(:allscripts_unity_client_parameters, :mode => :json)
expect(subject.create(parameters).client_type).to be(:json)
end
end

context 'when not given :mode' do
it 'returns a client with client_type :soap' do
savon.expects("GetSecurityToken").with(:message => :any).returns(get_security_token)
parameters = FactoryGirl.build(:allscripts_unity_client_parameters)
parameters[:mode] = nil
expect(subject.create(parameters).client_type).to be(:soap)
Expand Down

0 comments on commit e565b10

Please sign in to comment.