Sha256: ad6be819db61ba3e581c08195c6ffc6875b631f860ad670822cdc5cb9a0b21ab

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

module LifenFhir
  class Practitioner < Element

    attribute :channels, [LifenFhir::Channel]

    attribute :last_name, String
    attribute :first_name, String
    attribute :rpps, String

    def fhir_payload
      { reference: reference }
    end

    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

    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

    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

    private

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lifen_fhir-0.6.1 lib/lifen_fhir/practitioner.rb
lifen_fhir-0.6.0 lib/lifen_fhir/practitioner.rb
lifen_fhir-0.5.0 lib/lifen_fhir/practitioner.rb
lifen_fhir-0.4.2 lib/lifen_fhir/practitioner.rb