Class: XDS::RetrieveDocumentSetRequest

Inherits:
MTOMXopRequest show all
Defined in:
lib/xds/retrieve_document_set_request.rb

Instance Attribute Summary

Attributes inherited from XdsRequest

#endpoint_uri, #header, #proxy_host, #proxy_port

Instance Method Summary collapse

Methods inherited from XdsRequest

#to_soap

Constructor Details

#initialize(service_url, doc_ids = []) ⇒ RetrieveDocumentSetRequest

Returns a new instance of RetrieveDocumentSetRequest.



4
5
6
7
# File 'lib/xds/retrieve_document_set_request.rb', line 4

def initialize(service_url, doc_ids = [])
  super(service_url,"urn:ihe:iti:2007:RetrieveDocumentSet")
  @doc_ids = doc_ids
end

Instance Method Details

#add_ids_to_request(repository_unique_id, document_unique_id) ⇒ Object



9
10
11
12
# File 'lib/xds/retrieve_document_set_request.rb', line 9

def add_ids_to_request(repository_unique_id, document_unique_id)
  @doc_ids << {:repository_unique_id => repository_unique_id,
               :document_unique_id => document_unique_id}
end

#executeObject

Returns an array of hashes, with a hash for each document returned. The hash will contain

  • :repository_unique_id - The Repository Unique Id for the document

  • :document_unique_id - The Document Unique Id for the document

  • :content - The document as a String



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xds/retrieve_document_set_request.rb', line 19

def execute
  post = super
  parts = MIME::MimeMessageParser.parse(post.get_response_body_as_stream, 
                                        post.get_response_header("Content-Type").value)
  rdsr = XDS::RetrieveDocumentSetResponse.new
  rdsr.parse_soap_response(parts.first[:content])
  if rdsr.request_successful?
    docs = []
    rdsr.retrieved_documents.each do |rd|
      # hacky yes!, if rd has a content_id that means the response sent the document back as a separate entry in the multipart doc
      # else it sent it back as a base64 encoded string that has already been parsed by the rd object and set in :content of the returned hash
      part = rd[:content_id] ? parts.find {|candidate_part| candidate_part[:content_id].eql?('<' + rd[:content_id] + '>')} : rd
      doc = {}
      doc[:repository_unique_id] = rd[:repository_unique_id]
      doc[:document_unique_id] = rd[:document_unique_id]
      doc[:content] = part[:content]
      docs << doc
    end
    
    return docs
  else
    return false
  end
end

#get_partsObject



44
45
46
47
48
49
50
# File 'lib/xds/retrieve_document_set_request.rb', line 44

def get_parts
 body_part =  XdsPart.new("body", to_soap)
 body_part.char_set="UTF-8"
 body_part.id = UUID.new.generate
 body_part.set_content_type(%{application/xop+xml; type="application/soap+xml"})   
 [body_part]
end

#to_soap_body(builder, body_attributes = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/xds/retrieve_document_set_request.rb', line 53

def to_soap_body(builder,body_attributes = {})
  builder.soapenv(:Body, body_attributes) do
    builder.RetrieveDocumentSetRequest('xmlns' => "urn:ihe:iti:xds-b:2007") do
      @doc_ids.each do |doc_id|
        builder.DocumentRequest do
          builder.RepositoryUniqueId(doc_id[:repository_unique_id])
          builder.DocumentUniqueId(doc_id[:document_unique_id])
        end
      end
    end
  end
end