athena_health 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14f98cfaa15caca65ad1fbc036674eb76d38fd0a5bee50a4b20c64149d286cce
4
- data.tar.gz: ad2e1d5be5847a5f5bed1e4df4b583ab474ea15b2d60b807e9b671e5f698f5d9
3
+ metadata.gz: 72d528a701d5b4e4495d1e37121779dc39e6940e7dd761e199478e269c955f2e
4
+ data.tar.gz: 5849da85a6822b0a5f92f5c333ab51eb2cb75a8b9ea823a37282447b91651b0d
5
5
  SHA512:
6
- metadata.gz: 616b05bc653fd2722229718b9ba633cd19263d1dfadbaa0c15abbddc70c61703749343d5af14027f1fa583498491f4c490ac42d5e855e624e6cbce68f7facac5
7
- data.tar.gz: 709e309ceaf94ccd4a0c0b716d8bdb350d4d97f66f1079c416320ba0dfaf769979a8a66c25e30084c19b8df871ee532e233685de52547412f045aae57bfc1d9f
6
+ metadata.gz: 1209d763734ae0fed0e659d87841215a3db81da08abae384d7e50abfaea8c8d66dfc55901dee7de408958df04fad37273b9f57236dcdf4172de946b249819a96
7
+ data.tar.gz: d327001b2902eb318b97bd3b3d294809c77b6b06d20ceb9614a7608ee63e412314c80f992d5518637ff540a2b2cea051d7388b80586582e704f577f8822c6a17
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .idea
11
+ .vscode/settings.json
@@ -1,13 +1,12 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'athena_health/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = 'athena_health'
8
7
  spec.version = AthenaHealth::VERSION
9
- spec.authors = ["Mateusz Urbański"]
10
- spec.email = ['mateuszurbanski@yahoo.pl']
8
+ spec.authors = ['Mateusz Urbański', 'Ben Jones']
9
+ spec.email = ['mateuszurbanski@yahoo.pl', 'ben@benjones.io']
11
10
 
12
11
  spec.summary = 'Ruby wrapper for Athenahealth API.'
13
12
  spec.description = 'Ruby wrapper for Athenahealth API. See https://developer.athenahealth.com/io-docs for more details.'
@@ -18,11 +17,13 @@ Gem::Specification.new do |spec|
18
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
18
  spec.require_paths = ['lib']
20
19
 
21
- spec.add_dependency 'typhoeus'
22
- spec.add_dependency 'virtus'
20
+ spec.add_dependency 'typhoeus', '~> 1.4'
21
+ spec.add_dependency 'virtus', '~> 2.0'
23
22
 
24
23
  spec.add_development_dependency 'bundler', '~> 2.2.24'
25
24
  spec.add_development_dependency 'rake', '~> 10.0'
26
25
  spec.add_development_dependency 'rspec', '~> 3.2'
27
26
  spec.add_development_dependency 'vcr', '~> 3.0'
27
+ spec.add_development_dependency 'timecop', '~> 0.9.6'
28
+ spec.add_development_dependency 'rubocop', '~> 1.42'
28
29
  end
@@ -12,6 +12,7 @@ module AthenaHealth
12
12
  attribute :date, String
13
13
  attribute :departmentid, Integer
14
14
  attribute :duration, Integer
15
+ attribute :encounterid, Integer
15
16
  attribute :encounterstatus, String
16
17
  attribute :frozen, Boolean
17
18
  attribute :lastmodified, String
@@ -0,0 +1,69 @@
1
+ require 'json'
2
+
3
+ module AthenaHealth
4
+ class AuthToken
5
+ def initialize(client_id:, secret:, base_url:, api_version:, auth_token_hash: nil)
6
+ @base_url = base_url
7
+ @api_version = api_version
8
+ @client_id = client_id
9
+ @secret = secret
10
+ reset!
11
+ parse_auth_token_hash!(auth_token_hash) unless auth_token_hash.nil?
12
+ end
13
+
14
+ def auth_header
15
+ { 'Authorization' => "Bearer #{token}" }
16
+ end
17
+
18
+ def reset!
19
+ @access_token = nil
20
+ @expires_at = nil
21
+ end
22
+
23
+ def serialized_token
24
+ {
25
+ 'access_token' => token,
26
+ 'expires_at' => @expires_at.to_i
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def token
33
+ fetch_token! unless valid?
34
+ @access_token
35
+ end
36
+
37
+ def valid?
38
+ !@access_token.nil? &&
39
+ !@expires_at.nil? &&
40
+ @expires_at > Time.now
41
+ end
42
+
43
+ def parse_auth_token_hash!(auth_token_hash)
44
+ # make sure it has the right parts
45
+ return unless auth_token_hash['access_token'].instance_of? String
46
+ return unless auth_token_hash['expires_at'].instance_of? Integer
47
+
48
+ @access_token = auth_token_hash['access_token']
49
+ @expires_at = Time.at(auth_token_hash['expires_at'])
50
+ end
51
+
52
+ def fetch_token!
53
+ reset!
54
+ initiated_at = Time.now
55
+ response = Typhoeus.post(
56
+ "#{@base_url}/oauth2/#{@api_version}/token",
57
+ userpwd: "#{@client_id}:#{@secret}",
58
+ body: {
59
+ grant_type: 'client_credentials',
60
+ scope: 'athena/service/Athenanet.MDP.*'
61
+ }
62
+ )
63
+ token_hash = JSON.parse(response.response_body)
64
+ expires_in = token_hash['expires_in'].to_i
65
+ @access_token = token_hash['access_token']
66
+ @expires_at = initiated_at + expires_in
67
+ end
68
+ end
69
+ end
@@ -1,14 +1,27 @@
1
1
  module AthenaHealth
2
2
  class Client
3
- def initialize(production: false, client_id:, secret:, token: nil)
4
- @api = AthenaHealth::Connection.new(
5
- production: production,
3
+ PRODUCTION_BASE_URL = 'https://api.platform.athenahealth.com'.freeze
4
+ PREVIEW_BASE_URL = 'https://api.preview.platform.athenahealth.com'.freeze
5
+ API_VERSION = 'v1'.freeze
6
+
7
+ def initialize(client_id:, secret:, production: false, auth_token_hash: nil)
8
+ base_url = Client.base_url(production: production)
9
+ @token = AthenaHealth::AuthToken.new(
6
10
  client_id: client_id,
7
11
  secret: secret,
8
- token: token,
12
+ auth_token_hash: auth_token_hash,
13
+ base_url: base_url,
14
+ api_version: API_VERSION
15
+ )
16
+ @api = AthenaHealth::Connection.new(
17
+ base_url: base_url, api_version: API_VERSION, token: @token
9
18
  )
10
19
  end
11
20
 
21
+ def serialized_token
22
+ @token.serialized_token
23
+ end
24
+
12
25
  include Endpoints::Practices
13
26
  include Endpoints::Departments
14
27
  include Endpoints::Patients
@@ -20,5 +33,9 @@ module AthenaHealth
20
33
  include Endpoints::Subscriptions
21
34
  include Endpoints::Claims
22
35
  include Endpoints::CustomFields
36
+
37
+ def self.base_url(production:)
38
+ production ? PRODUCTION_BASE_URL : PREVIEW_BASE_URL
39
+ end
23
40
  end
24
41
  end
@@ -2,43 +2,23 @@ require 'json'
2
2
 
3
3
  module AthenaHealth
4
4
  class Connection
5
- PRODUCTION_BASE_URL = 'https://api.platform.athenahealth.com'.freeze
6
- PREVIEW_BASE_URL = 'https://api.preview.platform.athenahealth.com'.freeze
7
- API_VERSION = 'v1'.freeze
8
-
9
- def initialize(client_id:, secret:, token: nil, production: )
10
- @client_id = client_id
11
- @secret = secret
5
+ def initialize(base_url:, api_version:, token:)
12
6
  @token = token
13
- @production = production
14
- end
15
-
16
- def authenticate
17
- response = Typhoeus.post(
18
- "#{base_url}/oauth2/#{API_VERSION}/token",
19
- userpwd: "#{@client_id}:#{@secret}",
20
- body: {
21
- grant_type: 'client_credentials',
22
- scope: 'athena/service/Athenanet.MDP.*'
23
- }
24
- ).response_body
25
-
26
- @token = JSON.parse(response)['access_token']
7
+ @api_version = api_version
8
+ @base_url = base_url
27
9
  end
28
10
 
29
11
  def call(endpoint:, method:, params: {}, body: {}, second_call: false)
30
- authenticate if @token.nil?
31
-
32
12
  response = Typhoeus::Request.new(
33
- "#{base_url}/#{API_VERSION}/#{endpoint}",
13
+ "#{@base_url}/#{@api_version}/#{endpoint}",
34
14
  method: method,
35
- headers: { "Authorization" => "Bearer #{@token}"},
15
+ headers: @token.auth_header,
36
16
  params: params,
37
17
  body: body
38
18
  ).run
39
19
 
40
20
  if response.response_code == 401 && !second_call
41
- authenticate
21
+ @token.reset!
42
22
  return call(endpoint: endpoint, method: method, second_call: true, body: body, params: params)
43
23
  end
44
24
 
@@ -48,13 +28,9 @@ module AthenaHealth
48
28
 
49
29
  body = response.response_body
50
30
 
51
- if [400, 409].include? response.response_code
52
- fail AthenaHealth::ValidationError.new(json_response(body))
53
- end
31
+ raise AthenaHealth::ValidationError, json_response(body) if [400, 409].include? response.response_code
54
32
 
55
- if response.response_code != 200
56
- AthenaHealth::Error.new(code: response.response_code).render
57
- end
33
+ AthenaHealth::Error.new(code: response.response_code).render if response.response_code != 200
58
34
 
59
35
  json_response(body)
60
36
  end
@@ -64,9 +40,5 @@ module AthenaHealth
64
40
  def json_response(body)
65
41
  JSON.parse(body)
66
42
  end
67
-
68
- def base_url
69
- @base_url ||= @production ? PRODUCTION_BASE_URL : PREVIEW_BASE_URL
70
- end
71
43
  end
72
44
  end
@@ -8,7 +8,7 @@ module AthenaHealth
8
8
  params: params.merge!(departmentid: department_id, ordertype: order_type)
9
9
  )
10
10
 
11
- response.map {|facility| AthenaHealth::Facility.new(facility) }
11
+ response.map { |facility| AthenaHealth::Facility.new(facility) }
12
12
  end
13
13
 
14
14
  def all_medications(practice_id:, search_value:)
@@ -18,7 +18,7 @@ module AthenaHealth
18
18
  params: { searchvalue: search_value }
19
19
  )
20
20
 
21
- response.map {|medication| AthenaHealth::Medication.new(medication) }
21
+ response.map { |medication| AthenaHealth::Medication.new(medication) }
22
22
  end
23
23
 
24
24
  def all_allergies(practice_id:, search_value:)
@@ -28,7 +28,7 @@ module AthenaHealth
28
28
  params: { searchvalue: search_value }
29
29
  )
30
30
 
31
- response.map {|allergy| AthenaHealth::Allergy.new(allergy) }
31
+ response.map { |allergy| AthenaHealth::Allergy.new(allergy) }
32
32
  end
33
33
 
34
34
  def all_insurances(practice_id:, plan_name:, member_id:, state:, params: {})
@@ -54,6 +54,20 @@ module AthenaHealth
54
54
 
55
55
  response.map { |ordertype| AthenaHealth::OrderType.new(ordertype) }
56
56
  end
57
+
58
+ def all_gender_identities(practice_id:, show2015edcehrtvalues: nil, limit: nil, offset: nil)
59
+ params = {
60
+ show2015edcehrtvalues: show2015edcehrtvalues, limit: limit, offset: offset
61
+ }.reject { |_k, v| v.nil? }
62
+
63
+ GenderIdentityFieldCollection.new(
64
+ @api.call(
65
+ endpoint: "#{practice_id}/configuration/patients/genderidentity",
66
+ method: :get,
67
+ params: params
68
+ )
69
+ )
70
+ end
57
71
  end
58
72
  end
59
73
  end
@@ -0,0 +1,5 @@
1
+ module AthenaHealth
2
+ class GenderIdentityFieldCollection < BaseCollection
3
+ attribute :genderidentityfields, Array[String]
4
+ end
5
+ end
@@ -16,6 +16,7 @@ module AthenaHealth
16
16
  attribute :entitytype, String
17
17
  attribute :npi, Integer
18
18
  attribute :providertype, String
19
+ attribute :otherprovideridlist, Array[String]
19
20
 
20
21
  def fullname
21
22
  "#{firstname} #{lastname}"
@@ -1,3 +1,3 @@
1
1
  module AthenaHealth
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.3'.freeze
3
3
  end
data/lib/athena_health.rb CHANGED
@@ -3,6 +3,7 @@ require 'virtus'
3
3
 
4
4
  require 'athena_health/version'
5
5
  require 'athena_health/connection'
6
+ require 'athena_health/auth_token'
6
7
  require 'athena_health/error'
7
8
  require 'athena_health/endpoints/practices'
8
9
  require 'athena_health/endpoints/departments'
@@ -37,6 +38,7 @@ require 'athena_health/appointment_type_collection'
37
38
  require 'athena_health/appointment'
38
39
  require 'athena_health/appointment_waitlist'
39
40
  require 'athena_health/appointment_collection'
41
+ require 'athena_health/gender_identity_field_collection'
40
42
  require 'athena_health/insurance_package'
41
43
  require 'athena_health/insurance_package_collection'
42
44
  require 'athena_health/patient_appointment_reason'
metadata CHANGED
@@ -1,43 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: athena_health
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Urbański
8
+ - Ben Jones
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2022-12-06 00:00:00.000000000 Z
12
+ date: 2023-01-20 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: typhoeus
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ">="
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '0'
20
+ version: '1.4'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ">="
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '0'
27
+ version: '1.4'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: virtus
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: '2.0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '0'
41
+ version: '2.0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: bundler
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -94,10 +95,39 @@ dependencies:
94
95
  - - "~>"
95
96
  - !ruby/object:Gem::Version
96
97
  version: '3.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: timecop
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.9.6
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.9.6
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.42'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.42'
97
126
  description: Ruby wrapper for Athenahealth API. See https://developer.athenahealth.com/io-docs
98
127
  for more details.
99
128
  email:
100
129
  - mateuszurbanski@yahoo.pl
130
+ - ben@benjones.io
101
131
  executables: []
102
132
  extensions: []
103
133
  extra_rdoc_files: []
@@ -123,6 +153,7 @@ files:
123
153
  - lib/athena_health/appointment_type.rb
124
154
  - lib/athena_health/appointment_type_collection.rb
125
155
  - lib/athena_health/appointment_waitlist.rb
156
+ - lib/athena_health/auth_token.rb
126
157
  - lib/athena_health/balance.rb
127
158
  - lib/athena_health/base_collection.rb
128
159
  - lib/athena_health/base_model.rb
@@ -156,6 +187,7 @@ files:
156
187
  - lib/athena_health/error.rb
157
188
  - lib/athena_health/event.rb
158
189
  - lib/athena_health/facility.rb
190
+ - lib/athena_health/gender_identity_field_collection.rb
159
191
  - lib/athena_health/insurance.rb
160
192
  - lib/athena_health/insurance_collection.rb
161
193
  - lib/athena_health/insurance_package.rb