Class: LifenFhir::Communication

Inherits:
Element show all
Defined in:
lib/lifen_fhir/communication.rb

Constant Summary collapse

STATUS =
["preparation", "in-progress", "suspended", "aborted", "completed" , "entered-in-error"]

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



47
48
49
50
51
52
53
54
# File 'lib/lifen_fhir/communication.rb', line 47

def method_missing(method, *arguments, &block)
  attribute_name = method.to_s.gsub!('is_', '')
  if STATUS.include? attribute_name
    self.status == attribute_name
  else
    super
  end
end

Class Method Details

.find_by_uuid(uuid) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/lifen_fhir/communication.rb', line 16

def self.find_by_uuid(uuid)
  json = application_client.get("fhir/Communication/#{uuid}")

  communication = new
  communication.attributes_from_json(json)

  communication
end

Instance Method Details

#attributes_from_json(json) ⇒ Object

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lifen_fhir/communication.rb', line 25

def attributes_from_json(json)
  self.uuid = json["id"]

  self.status = json.fetch("status")

  self.sent_at = json.fetch("sent") { "unknown" }

  self.received_at = json["received"]

  self.binary = Binary.new.attributes_from_json(Array(json["payload"]).first)

  self.sender = Practitioner.new.attributes_from_json(json["sender"])

  self.recipient = patient_or_practitioner(json["recipient"])

  self.medium = Medium.new.attributes_from_json(extract_json_for_medium(json["medium"]))

  raise Error.new(message: "Invalid Communication: status must be in the authorized values") if !valid?

  self
end