Class: LifenFhir::Practitioner

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#attributes_from_json, #fhir_payload_as_reference, #reference

Class Method Details

.find_by_rpps(rpps) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lifen_fhir/practitioner.rb', line 14

def self.find_by_rpps(rpps)
  json = application_client.get("fhir/Practitioner/?identifier=#{rpps}")

  raise "Practitioner not found" if Array(json["entry"]).size != 1

  user_json = Array(json["entry"]).first.fetch("resource") { {} }

  user_json[:uuid]                 = user_json["id"]

  user = new(user_json)

  Array(user_json["telecom"]).each do |telecom_json|
    user.channels <<  LifenFhir::Channel.from_json(telecom_json, "telecom")
  end

  Array(user_json["address"]).each do |address_json|
    user.channels <<  LifenFhir::Channel.from_json(address_json, "address")
  end

  user
end

Instance Method Details

#create_address(params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lifen_fhir/practitioner.rb', line 36

def create_address(params)
  filtered_params = {"resourceType" => "Practitioner"}

  address = Address.new(params)
  filtered_params[params[:type]] = address.fhir_payload

  json = application_client.post("fhir/#{reference}/$add-address", filtered_params)

  channel = Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: "#{Array(params[:lines]).join(", ")}, #{params[:postal_code]} #{params[:city]}")

  self.channels << channel

  channel
end

#create_telecom(params) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lifen_fhir/practitioner.rb', line 51

def create_telecom(params)
  filtered_params = {"resourceType" => "Practitioner"}

  telecom = Telecom.new(params)
  filtered_params[params[:type]] = telecom.fhir_payload

  json = application_client.post("fhir/#{reference}/$add-telecom", filtered_params)

  channel = Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: params[:value])

  self.channels << channel

  channel

end

#fhir_payloadObject



10
11
12
# File 'lib/lifen_fhir/practitioner.rb', line 10

def fhir_payload
  { reference: reference }
end