Class: Redox::Models::AbstractModel
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- Redox::Models::AbstractModel
show all
- Includes:
- Hashie::Extensions::IgnoreUndeclared, Hashie::Extensions::IndifferentAccess
- Defined in:
- lib/redox/models/model.rb
Direct Known Subclasses
Administration, Component, Contact, Demographics, Financial, Identifier, Media, MediaUpload, Medication, Medications, Model, Note, Notes, Notification, OrderingProvider, Scheduling, Transaction
Constant Summary
collapse
- HIGH_LEVEL_KEYS =
%w[Meta Patient Visit PotentialMatches]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_response(response) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/redox/models/model.rb', line 37
def self.from_response(response)
model = Model.new
model.response = response
HIGH_LEVEL_KEYS.each do |k|
begin
model.send("#{k}=", Module.const_get("Redox::Models::#{k}").new(response[k])) if response[k]
rescue
end
end
return model
end
|
.from_response_inflected(response) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/redox/models/model.rb', line 51
def self.from_response_inflected(response)
model = self.from_response(response)
if (model.response.ok?)
data = model.response.parsed_response
if data.respond_to?(:keys)
model_class = nil
if model.meta&.data_model
model_class = "Redox::Models::#{model.meta.data_model}"
begin
model_class = Object.const_get(model_class)
rescue NameError
model_class = nil
end
end
data.keys.each do |key|
next if HIGH_LEVEL_KEYS.include?(key.to_s)
helper_name = key.to_s.downcase.to_sym
if model_class.nil?
model.define_singleton_method(helper_name) { data[key] }
else
if data[key].is_a?(Array)
model.define_singleton_method(helper_name) { data[key].map {|obj| model_class.new(obj) } }
else
model.define_singleton_method(helper_name) { model_class.new(data[key]) }
end
end
end
end
end
return model
end
|
Instance Method Details
#insurances ⇒ Object
33
34
35
|
# File 'lib/redox/models/model.rb', line 33
def insurances
(self.patient&.insurances || []) + (self.visit&.insurances || [])
end
|
#to_json(args = {}) ⇒ Object
29
30
31
|
# File 'lib/redox/models/model.rb', line 29
def to_json(args = {})
return self.to_h.to_json
end
|