Class: AllscriptsApi::Documents::DocumentSender

Inherits:
Object
  • Object
show all
Defined in:
lib/allscripts_api/documents/document_sender.rb

Overview

Wraps AllscriptsApi::Documents::Document.build_xml and AllscriptsApi::Documents::DocumentMethods#save_document_image to handle the 2 step document image saving process The DocumentSender is set up to send the document as one big chunk

Instance Method Summary collapse

Constructor Details

#initialize(client, document, file_name, params) ⇒ AllscriptsApi::Documents::DocumentSender

rubocop:disable LineLength The new method sets up eerything needed to run #send_document

rubocop:enable LineLength

Examples:

Usage Example

document_params =
  {
    bytes_read: pdf.bytes.length,
    b_done_upload: false,
    document_var: "",
    patient_id: 19,
    owner_code: "TW0001",
    first_name: "Allison",
    last_name: "Allscripts",
    document_type: "sEKG", # Document_Type_DE dictionary
    organization_name: "New World Health"
  }
ds = AllscriptsApi::Documents::DocumentSender.new(client, pdf, "test.pdf", document_params)
ds.send_document

Parameters:

  • client (AllscriptsApi::Client)

    pass in an authorized client

  • document (String)

    the string contents of the pdf to be saved

  • file_name (String)

    the name of the file to be saved, usually ending in .pdf

  • params (Hash)

    a hash of params for use in saving a document

Raises:

See Also:

  • for details


36
37
38
39
40
41
42
43
# File 'lib/allscripts_api/documents/document_sender.rb', line 36

def initialize(client, document, file_name, params)
  @params = params
  @patient_id = @params[:patient_id]
  raise MissingRequiredParamsError, "patient_id required" unless @patient_id
  @client = client
  @document = Base64.encode64(document)
  @file_name = file_name
end

Instance Method Details

#send_documentHash, MagicError

Sends the document in 2 steps, first the doc itself, then a confirmation that it is done and ready to be saved.

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/allscripts_api/documents/document_sender.rb', line 48

def send_document
  @params[:b_done_upload] = "false"
  first_step_xml =
    Documents::Document.build_xml(@file_name, "i", @params)
  results =
    @client.save_document_image(@patient_id,
                                first_step_xml, @document)
  @params[:b_done_upload] = "true"
  @params[:document_var] = results[0]["documentVar"]
  second_step_xml =
    Documents::Document.build_xml(@file_name, "i", @params)
  @client.save_document_image(@patient_id,
                              second_step_xml, @document)
end