Sha256: 679d0cb4622991bab409042c03c8d735a4954dacfb4b0a1806c6034cc4c020fa

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Lifen
  module Communication
    class Request < Lifen::Base

      attribute :uuid, String

      attribute :sender, Lifen::User
      attribute :recipient, Lifen::User

      attribute :channel, Lifen::Communication::Channel
      attribute :attachment, Lifen::Communication::Attachment

      def send
        json = application_client.post("fhir/CommunicationRequest", fhir_payload)

        self.uuid = json["id"]

        raise "Communication request failed" if json["issue"].first["diagnostics"] != "CommunicationRequest accepted"

        self
      end

    private

      def fhir_payload
        {
          resourceType: "CommunicationRequest",
          sender: [ sender.fhir_payload ],
          recipient: [ recipient.fhir_payload ],
          contained: [ channel.fhir_payload(recipient) ],
          category: [ default_category],
          payload: [ attachment.fhir_payload ],
        }
      end

      def default_category
        {
          coding: [
             {
                system: "http://honestica.com/fhir/communication/category",
                code: "MEDICAL_REPORT"
             }
          ]
        }
      end

      def application_client
        @application_client ||= AppAuthenticatedClient.new
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lifen-1.6.2 lib/lifen/communication/request.rb
lifen-1.6.1 lib/lifen/communication/request.rb
lifen-1.6.0 lib/lifen/communication/request.rb