[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[orca-tech:01868] Re: PHPでの新APIの利用法を教えてください



ついでに、rubyでorcaの新apiのプログラム参考に、
今回のPHP使った患者情報取得と同等の
rubyでREXML使ったプログラムも組んでみました。
ご批評お願いします

-----patientget.rb-----

#!/usr/bin/ruby

require 'uri'
require 'net/http'
require "rexml/document"

Net::HTTP.version_1_2

HOST = "localhost"
PORT = "8000"
USER = "ormaster"
PASSWD = "ormaster123"
ID = ARGV[0]

# Version 4.5
#req = Net::HTTP::Get.new("/orca12/patientget?id=#{ID}")
# Version 4.6
req = Net::HTTP::Get.new("/api01r/patientget?id=#{ID}")

req.basic_auth(USER, PASSWD)

out_f = open("tmp.xml", "w") 

Net::HTTP.start(HOST, PORT) { |http|
  res = http.request(req)
  out_f.puts res.body
}

out_f.close

include REXML    

doc = REXML::Document.new(open("tmp.xml"))

doc.elements.each('data/record/record/record/string') do |element|
  if element.text==nil then
  else
    rs = element.attributes["name"] 
    rs << ","
    rs << element.text
    puts rs
  end
end


doc.elements.each('data/record/record/record/record/string') do |element|
  if element.text==nil then
  else
    rs = element.attributes["name"] 
    rs << ","
    rs << element.text
    puts rs
  end
end

doc.elements.each('data/record/record/record/array/record/string') do |element
|

  if element.text==nil then
  else
    rs=element.attributes["name"] 
    rs << ","
    rs << element.text
    puts rs
  end
end

-----------------------------

ゆうえん医院@岡山