Class: Lifen::Practitioner
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_by_rpps(rpps) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lifen/practitioner.rb', line 15 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 << Lifen::Channel.from_json(telecom_json, "telecom") end Array(user_json["address"]).each do |address_json| user.channels << Lifen::Channel.from_json(address_json, "address") end user end |
.from_json(json) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/lifen/practitioner.rb', line 58 def self.from_json(json) reference = json["reference"] uuid = reference.gsub("Practitioner/", "") new(uuid: uuid) end |
Instance Method Details
#create_address(params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lifen/practitioner.rb', line 37 def create_address(params) filtered_params = {"resourceType" => "Practitioner"} address = { "line": Array(params[:lines]), "city": params[:city], "postalCode": params[:postal_code], "country": params[:country] } filtered_params[params[:type]] = address json = application_client.post("fhir/Practitioner/#{uuid}/$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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lifen/practitioner.rb', line 66 def create_telecom(params) filtered_params = {"resourceType" => "Practitioner"} telecom = { "system": params[:system], "value": params[:value] } filtered_params[params[:type]] = telecom json = application_client.post("fhir/Practitioner/#{uuid}/$add-telecom", filtered_params) channel = Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: params[:value]) self.channels << channel channel end |
#fhir_payload ⇒ Object
11 12 13 |
# File 'lib/lifen/practitioner.rb', line 11 def fhir_payload { reference: "Practitioner/#{uuid}" } end |