Class: LifenFhir::CommunicationRequest
- Inherits:
-
Element
show all
- Defined in:
- lib/lifen_fhir/communication_request.rb
Constant Summary
collapse
- PAYLOAD_ATTRIBUTES =
["sender", "recipient", "payload", "category"]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Element
#fhir_payload_as_reference, #reference
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/lifen_fhir/communication_request.rb', line 77
def method_missing(method, *arguments, &block)
attribute_name = method.to_s.gsub!('has_', '')
if PAYLOAD_ATTRIBUTES.include? attribute_name
json_payload.key?(attribute_name)
else
super
end
end
|
Class Method Details
.find_by_uuid(uuid) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/lifen_fhir/communication_request.rb', line 32
def self.find_by_uuid(uuid)
json = application_client.get("fhir/CommunicationRequest/#{uuid}")
communication_request = new
communication_request.attributes_from_json(json)
communication_request
end
|
Instance Method Details
#attributes_from_json(json) ⇒ Object
50
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
|
# File 'lib/lifen_fhir/communication_request.rb', line 50
def attributes_from_json(json)
self.json_payload = json
self.uuid = json["id"]
self.status = json.fetch("status") { "unknown" }
if has_payload
self.binary = Binary.new.attributes_from_json(Array(json["payload"]).first)
end
if has_category
self.category = Category.new.attributes_from_json(Array(json["category"]).first)
end
if has_sender
self.sender = Practitioner.new.attributes_from_json(json["sender"])
end
if has_recipient
self.recipients = Array(json["recipient"]).map do |recipient_json|
Practitioner.new.attributes_from_json(recipient_json)
end
end
end
|
#communications ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/lifen_fhir/communication_request.rb', line 41
def communications
if !@communications_loaded
load_communications
@communications_loaded = true
end
@communications
end
|
#send ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/lifen_fhir/communication_request.rb', line 23
def send
json = application_client.post("fhir/CommunicationRequest", fhir_payload)
self.uuid = json["id"]
self.number_communications = Array(json["issue"]).length
self
end
|