class Lifen::Practitioner

Public Class Methods

find_by_rpps(rpps) click to toggle source
# 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) click to toggle source
# File lib/lifen/practitioner.rb, line 58
def self.from_json(json)
  reference = json["reference"]

  uuid = reference.gsub("Practitioner/", "")

  new(uuid: uuid)
end

Private Class Methods

application_client() click to toggle source
# File lib/lifen/practitioner.rb, line 92
def self.application_client
  @application_client ||= AppAuthenticatedClient.new
end

Public Instance Methods

create_address(params) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/lifen/practitioner.rb, line 11
def fhir_payload
  { reference: "Practitioner/#{uuid}" }
end

Private Instance Methods

application_client() click to toggle source
# File lib/lifen/practitioner.rb, line 88
def application_client
  @application_client ||= AppAuthenticatedClient.new
end