daisybill_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +20 -0
- data/lib/daisybill_api.rb +53 -0
- data/lib/daisybill_api/configuration.rb +46 -0
- data/lib/daisybill_api/data.rb +7 -0
- data/lib/daisybill_api/data/client.rb +66 -0
- data/lib/daisybill_api/data/rest_client/payload.rb +30 -0
- data/lib/daisybill_api/data/url.rb +26 -0
- data/lib/daisybill_api/ext.rb +20 -0
- data/lib/daisybill_api/ext/associations.rb +39 -0
- data/lib/daisybill_api/ext/attributes.rb +103 -0
- data/lib/daisybill_api/ext/attributes/attribute.rb +60 -0
- data/lib/daisybill_api/ext/attributes/type_castings.rb +78 -0
- data/lib/daisybill_api/ext/crud.rb +147 -0
- data/lib/daisybill_api/ext/crud/create.rb +107 -0
- data/lib/daisybill_api/ext/crud/destroy.rb +28 -0
- data/lib/daisybill_api/ext/crud/index.rb +41 -0
- data/lib/daisybill_api/ext/crud/show.rb +22 -0
- data/lib/daisybill_api/ext/crud/update.rb +37 -0
- data/lib/daisybill_api/ext/links.rb +65 -0
- data/lib/daisybill_api/ext/links/link.rb +35 -0
- data/lib/daisybill_api/ext/pageable_collection.rb +124 -0
- data/lib/daisybill_api/models.rb +22 -0
- data/lib/daisybill_api/models/address.rb +16 -0
- data/lib/daisybill_api/models/attachment.rb +22 -0
- data/lib/daisybill_api/models/base.rb +29 -0
- data/lib/daisybill_api/models/bill.rb +42 -0
- data/lib/daisybill_api/models/bill_payment.rb +22 -0
- data/lib/daisybill_api/models/bill_submission.rb +18 -0
- data/lib/daisybill_api/models/billing_provider.rb +25 -0
- data/lib/daisybill_api/models/claims_administrator.rb +13 -0
- data/lib/daisybill_api/models/contact.rb +19 -0
- data/lib/daisybill_api/models/employer.rb +13 -0
- data/lib/daisybill_api/models/injury.rb +30 -0
- data/lib/daisybill_api/models/patient.rb +32 -0
- data/lib/daisybill_api/models/place_of_service.rb +29 -0
- data/lib/daisybill_api/models/referring_provider.rb +21 -0
- data/lib/daisybill_api/models/rendering_provider.rb +23 -0
- data/lib/daisybill_api/models/service_line_item.rb +27 -0
- data/lib/daisybill_api/version.rb +3 -0
- data/spec/daisybill_api/configuration_spec.rb +16 -0
- data/spec/daisybill_api/data/client_spec.rb +47 -0
- data/spec/daisybill_api/data/rest_client/payload_spec.rb +17 -0
- data/spec/daisybill_api/data/url_spec.rb +13 -0
- data/spec/daisybill_api/ext/attributes/attribute_spec.rb +120 -0
- data/spec/daisybill_api/ext/attributes/type_castings_spec.rb +50 -0
- data/spec/daisybill_api/ext/links/link_spec.rb +50 -0
- data/spec/daisybill_api/ext/pageable_collection_spec.rb +145 -0
- data/spec/daisybill_api/models/address_spec.rb +7 -0
- data/spec/daisybill_api/models/attachment_spec.rb +9 -0
- data/spec/daisybill_api/models/bill_payment_spec.rb +11 -0
- data/spec/daisybill_api/models/bill_spec.rb +22 -0
- data/spec/daisybill_api/models/bill_submission_spec.rb +9 -0
- data/spec/daisybill_api/models/billing_provider_spec.rb +13 -0
- data/spec/daisybill_api/models/claims_administrator_spec.rb +7 -0
- data/spec/daisybill_api/models/contact_spec.rb +6 -0
- data/spec/daisybill_api/models/employer_spec.rb +7 -0
- data/spec/daisybill_api/models/injury_spec.rb +13 -0
- data/spec/daisybill_api/models/patient_spec.rb +14 -0
- data/spec/daisybill_api/models/place_of_service_spec.rb +14 -0
- data/spec/daisybill_api/models/referring_provider_spec.rb +11 -0
- data/spec/daisybill_api/models/rendering_provider_spec.rb +12 -0
- data/spec/daisybill_api/models/service_line_item_spec.rb +11 -0
- data/spec/daisybill_api_spec.rb +35 -0
- metadata +289 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Ext
|
3
|
+
module CRUD
|
4
|
+
module Show
|
5
|
+
module ClassMethods
|
6
|
+
# === Retrieving a record
|
7
|
+
#
|
8
|
+
# DaisybillApi::Models::BillingProvider.find(14) # => <DaisybillApi::Models::BillingProvider id: 14...>
|
9
|
+
#
|
10
|
+
# If a record is not found, nil is returned
|
11
|
+
def find(id)
|
12
|
+
c = client :get, show_path(id)
|
13
|
+
new(c.response) if c.success?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @private
|
18
|
+
module InstanceMethods; end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Ext
|
3
|
+
module CRUD
|
4
|
+
module Update
|
5
|
+
# @private
|
6
|
+
module ClassMethods; end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
|
10
|
+
# === Updating a record
|
11
|
+
#
|
12
|
+
# pt = DaisybillApi::Models::Patient.find(12) # => <DaisybillApi::Models::Patient id: 12...>
|
13
|
+
#
|
14
|
+
# pt.telephone # => "2138888888"
|
15
|
+
#
|
16
|
+
# pt.telephone = "2137777777" # => "2137777777"
|
17
|
+
#
|
18
|
+
# pt.telephone # => "2137777777"
|
19
|
+
#
|
20
|
+
# pt.save # => true
|
21
|
+
def save
|
22
|
+
return update unless new_record?
|
23
|
+
return create if respond_to? :create
|
24
|
+
message = '#save method is not supported for new record'
|
25
|
+
DaisybillApi.logger.error message
|
26
|
+
raise NotImplementedError.new message
|
27
|
+
end
|
28
|
+
|
29
|
+
# @private
|
30
|
+
def update
|
31
|
+
send_data :patch, show_path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'daisybill_api/ext/links/link'
|
2
|
+
|
3
|
+
module DaisybillApi
|
4
|
+
module Ext
|
5
|
+
# @private
|
6
|
+
module Links
|
7
|
+
module ClassMethods
|
8
|
+
def link(name, options = {})
|
9
|
+
clazz = modulize options[:class]
|
10
|
+
links[name] = l = Link.new name, clazz, options
|
11
|
+
attribute l.foreign_key, :integer if l.foreign_key?
|
12
|
+
define_method(name) { read_link(name).value }
|
13
|
+
end
|
14
|
+
|
15
|
+
def links
|
16
|
+
@links ||= {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module InstanceMethods
|
21
|
+
def initialize(attributes)
|
22
|
+
lnks = attributes.delete 'links'
|
23
|
+
super(attributes)
|
24
|
+
class_links.each { |link| links[link.name] = link.clone }
|
25
|
+
self.links = lnks
|
26
|
+
end
|
27
|
+
|
28
|
+
def links=(values)
|
29
|
+
return if values.nil?
|
30
|
+
values.each { |link| write_link link['rel'], link['href'] }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def read_link(name)
|
36
|
+
links[name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def write_link(name, href)
|
40
|
+
if link = links[name.to_sym]
|
41
|
+
link.href = href
|
42
|
+
self.send("#{link.foreign_key}=", link.foreign_id) if href && link.foreign_key?
|
43
|
+
else
|
44
|
+
DaisybillApi.logger.debug "Was trying to set unexisting link #{name.inspect} with #{href.inspect}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def class_links
|
49
|
+
@class_links ||= self.class.links.values
|
50
|
+
end
|
51
|
+
|
52
|
+
def links
|
53
|
+
@links ||= {}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.included(base)
|
58
|
+
base.class_eval do
|
59
|
+
include DaisybillApi::Ext::Links::InstanceMethods
|
60
|
+
extend DaisybillApi::Ext::Links::ClassMethods
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Ext
|
3
|
+
module Links
|
4
|
+
class Link
|
5
|
+
attr_accessor :href
|
6
|
+
attr_reader :name, :klass
|
7
|
+
|
8
|
+
def initialize(name, klass, options = {})
|
9
|
+
@name = name
|
10
|
+
@klass = klass
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def value
|
15
|
+
return unless href
|
16
|
+
default_path = DaisybillApi::Data::Url::DEFAULT_PATH
|
17
|
+
c = DaisybillApi::Data::Client.build(:get, href.gsub(default_path, ''))
|
18
|
+
klass.constantize.new(c.response) if c.success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def foreign_key
|
22
|
+
@foreign_key ||= @options.has_key?(:foreign_key) ? @options[:foreign_key] : "#{name}_id"
|
23
|
+
end
|
24
|
+
|
25
|
+
def foreign_key?
|
26
|
+
!@options.has_key?(:foreign_key) || !!@options[:foreign_key]
|
27
|
+
end
|
28
|
+
|
29
|
+
def foreign_id
|
30
|
+
href.split('/').last
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Ext
|
3
|
+
|
4
|
+
# Provides a paginated collection of objects that can iterated upon:
|
5
|
+
#
|
6
|
+
# bp = DaisybillApi::Models::BillingProvider.find(14) # => <DaisyBillApi::Models::BillingProvider>
|
7
|
+
# patients = bp.patients # => #<DaisybillApi::Ext::PageableCollection>
|
8
|
+
#
|
9
|
+
# until patients.next_page.nil? do
|
10
|
+
# puts patients.map(&:id)
|
11
|
+
# patients = patients.next_page
|
12
|
+
# end
|
13
|
+
# # => [1, 2, 3, 4, 5]
|
14
|
+
class PageableCollection
|
15
|
+
include Enumerable
|
16
|
+
|
17
|
+
def initialize(entries, options = {})
|
18
|
+
@entries = entries
|
19
|
+
@options = options
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
"#<DaisybillApi::Ext::PageableCollection entries: #{entries.to_s[1..80]}..., previous_page: #{previous_page_number}, current_page: #{current_page_number}, next_page: #{next_page_number} >"
|
24
|
+
end
|
25
|
+
|
26
|
+
def each(&block)
|
27
|
+
entries.each do |entry|
|
28
|
+
block.call(entry)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the first page of the collection
|
33
|
+
#
|
34
|
+
# @patients = DaisybillApi::Models::Patient.all(billing_provider_id: 25) # => #<DaisybillApi::Ext::PageableCollection>
|
35
|
+
#
|
36
|
+
# @patients.first_page # => #<DaisybillApi::Ext::PageableCollection>
|
37
|
+
#
|
38
|
+
# @return [PageableCollection]
|
39
|
+
def first_page
|
40
|
+
resource_class.all(default_options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the last page in the collection
|
44
|
+
#
|
45
|
+
# @patients.last_page # => #<DaisybillApi::Ext::PageableCollection>
|
46
|
+
#
|
47
|
+
# @return [PageableCollection]
|
48
|
+
def last_page
|
49
|
+
resource_class.all(default_options.merge(page: total_page_count))
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns the next page in the collection
|
53
|
+
#
|
54
|
+
# @providers.next_page # => #<DaisybillApi::Ext::PageableCollection>
|
55
|
+
#
|
56
|
+
# @return [PageableCollection, nil]
|
57
|
+
def next_page
|
58
|
+
if next_page_number
|
59
|
+
resource_class.all(default_options.merge(page: next_page_number))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the previous page in the collection
|
64
|
+
#
|
65
|
+
# @providers.previous_page # => #<DaisybillApi::Ext::PageableCollection>
|
66
|
+
#
|
67
|
+
# @return [PageableCollection, nil]
|
68
|
+
def previous_page
|
69
|
+
if previous_page_number
|
70
|
+
resource_class.all(default_options.merge(page: previous_page_number))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the current page number
|
75
|
+
#
|
76
|
+
# @providers.current_page_number # => 1
|
77
|
+
#
|
78
|
+
# @return [Integer]
|
79
|
+
def current_page_number
|
80
|
+
retrieve_header_value(:x_page)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
attr_reader :options, :entries
|
86
|
+
|
87
|
+
def default_options
|
88
|
+
params.merge(per_page: results_per_page)
|
89
|
+
end
|
90
|
+
|
91
|
+
def headers
|
92
|
+
@headers ||= options[:headers] || {}
|
93
|
+
end
|
94
|
+
|
95
|
+
def params
|
96
|
+
@params ||= options[:params] || {}
|
97
|
+
end
|
98
|
+
|
99
|
+
def resource_class
|
100
|
+
@resource_class ||= options[:resource_class]
|
101
|
+
end
|
102
|
+
|
103
|
+
def previous_page_number
|
104
|
+
retrieve_header_value(:x_prev_page)
|
105
|
+
end
|
106
|
+
|
107
|
+
def next_page_number
|
108
|
+
retrieve_header_value(:x_next_page)
|
109
|
+
end
|
110
|
+
|
111
|
+
def results_per_page
|
112
|
+
headers[:x_per_page]
|
113
|
+
end
|
114
|
+
|
115
|
+
def total_page_count
|
116
|
+
headers[:x_total_pages]
|
117
|
+
end
|
118
|
+
|
119
|
+
def retrieve_header_value(key)
|
120
|
+
headers[key].to_s.empty? ? nil : headers[key].to_i
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'daisybill_api/models/address'
|
2
|
+
require 'daisybill_api/models/contact'
|
3
|
+
require 'daisybill_api/models/base'
|
4
|
+
require 'daisybill_api/models/claims_administrator'
|
5
|
+
require 'daisybill_api/models/bill_submission'
|
6
|
+
require 'daisybill_api/models/billing_provider'
|
7
|
+
require 'daisybill_api/models/employer'
|
8
|
+
require 'daisybill_api/models/injury'
|
9
|
+
require 'daisybill_api/models/patient'
|
10
|
+
require 'daisybill_api/models/place_of_service'
|
11
|
+
require 'daisybill_api/models/referring_provider'
|
12
|
+
require 'daisybill_api/models/rendering_provider'
|
13
|
+
require 'daisybill_api/models/attachment'
|
14
|
+
require 'daisybill_api/models/service_line_item'
|
15
|
+
require 'daisybill_api/models/bill'
|
16
|
+
require 'daisybill_api/models/bill_payment'
|
17
|
+
|
18
|
+
module DaisybillApi
|
19
|
+
# @private
|
20
|
+
module Models
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Models
|
3
|
+
class Address
|
4
|
+
include DaisybillApi::Ext::Attributes
|
5
|
+
|
6
|
+
attribute :id, :integer, readonly: true
|
7
|
+
attributes(
|
8
|
+
address_1: :string,
|
9
|
+
address_2: :string,
|
10
|
+
city: :string,
|
11
|
+
state: :string,
|
12
|
+
zip_code: :string
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Models
|
3
|
+
class Attachment < DaisybillApi::Models::Base
|
4
|
+
rest_actions :index, :create, :update, :show, :destroy
|
5
|
+
path_prefix '/bills', :bill_id
|
6
|
+
|
7
|
+
attributes(
|
8
|
+
id: :integer,
|
9
|
+
document_url: :string,
|
10
|
+
inactive: :boolean,
|
11
|
+
readonly: true
|
12
|
+
)
|
13
|
+
|
14
|
+
attributes(
|
15
|
+
report_type: :string,
|
16
|
+
document: :attachment
|
17
|
+
)
|
18
|
+
|
19
|
+
link :bill, class: 'Bill'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module DaisybillApi
|
4
|
+
module Models
|
5
|
+
class Base
|
6
|
+
include ActiveModel::Validations
|
7
|
+
include ActiveModel::Naming
|
8
|
+
extend DaisybillApi::Ext
|
9
|
+
|
10
|
+
attr_accessor :external_errors
|
11
|
+
|
12
|
+
validate :external
|
13
|
+
|
14
|
+
def initialize(attrs = {})
|
15
|
+
self.external_errors = {}
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def external
|
22
|
+
return if external_errors.blank?
|
23
|
+
external_errors.each { |field, errors|
|
24
|
+
errors.each { |error| self.errors.add field, error }
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Models
|
3
|
+
class Bill < DaisybillApi::Models::Base
|
4
|
+
path_prefix '/injuries', :injury_id
|
5
|
+
rest_actions :index, :show, :create, :update, :destroy
|
6
|
+
|
7
|
+
attributes(
|
8
|
+
id: :integer,
|
9
|
+
status: :string,
|
10
|
+
charge_cents: :integer,
|
11
|
+
expected_payment_cents: :integer,
|
12
|
+
allowed_cents: :integer,
|
13
|
+
balance_due_cents: :integer,
|
14
|
+
write_off_cents: :integer,
|
15
|
+
review_status: :string,
|
16
|
+
review_errors: [:string],
|
17
|
+
readonly: true,
|
18
|
+
)
|
19
|
+
|
20
|
+
attributes(
|
21
|
+
date_of_service: :date,
|
22
|
+
authorization_number: :string,
|
23
|
+
admission_date: :date,
|
24
|
+
practice_bill_id: :string,
|
25
|
+
additional_information: :string,
|
26
|
+
diagnosis_type: :string,
|
27
|
+
diagnosis_codes: [:string],
|
28
|
+
service_line_items: [DaisybillApi::Models::ServiceLineItem]
|
29
|
+
)
|
30
|
+
|
31
|
+
link :injury, class: 'Injury'
|
32
|
+
link :place_of_service, class: 'PlaceOfService'
|
33
|
+
link :rendering_provider, class: 'RenderingProvider'
|
34
|
+
link :referring_provider, class: 'ReferringProvider'
|
35
|
+
link :supervising_provider, class: 'RenderingProvider'
|
36
|
+
|
37
|
+
has_many :attachments, class: 'Attachment'
|
38
|
+
has_many :bill_payments, class: 'BillPayment'
|
39
|
+
has_many :bill_submissions, class: 'BillSubmission'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module DaisybillApi
|
2
|
+
module Models
|
3
|
+
class BillPayment < DaisybillApi::Models::Base
|
4
|
+
rest_actions :index
|
5
|
+
path_prefix '/bills', :bill_id
|
6
|
+
|
7
|
+
attributes(
|
8
|
+
id: :integer,
|
9
|
+
payment_amount_cents: :integer,
|
10
|
+
check_amount: :integer,
|
11
|
+
check_number: :string,
|
12
|
+
check_effective_date: :date,
|
13
|
+
payment_source: :string,
|
14
|
+
readonly: true
|
15
|
+
)
|
16
|
+
|
17
|
+
link :bill_submission, class: 'BillSubmission'
|
18
|
+
link :bill, class: 'Bill'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|