先日ORCAカンファレンス2016に参加してきたのですが、今後はデータベースから直接データを取得するのではなく、APIから取得してくださいと言われたので、シェルスクリプトからでもできるのか挑戦してみました。
ここでの例は、ORCAサーバーのホストがlocalhost、ポートが8000、ユーザー名がormaster、パスワードがpassword、患者番号は000001です。
APIはGETメソッドで取得できるため、curlコマンドが使えそうです。また、結果はXMLで返ってくるため、xmllintコマンドで必要なデータを抽出できそうです。xmllitコマンドはlibxml2-utilsパッケージに含まれているため、最初にインストールしてください。
まずはHTTPヘッダーを確認します。次のコマンドを実行します。
$ curl -X GET 'http://localhost:8000/api01rv2/patientgetv2?id=000001' -I -u ormaster:password
次の結果が返ってくれば成功です。
HTTP/1.1 200 OK
Date: Tue, 05 Jul 2016 05:46:43 GMT
Server: glserver/1.4.9
Content-Type: application/xml
Content-Length: 2500
HTTPのステータスの意味を解説したりはしません。
いよいよ患者情報のXMLを取得します。
$ curl -X GET 'http://localhost:8000/api01rv2/patientgetv2?id=000001' -u ormaster:password -o patient.xml
取得したXMLをpatient.xmlとして保存しています。
patient.xmlの中身を確認します。
$ xmllint --shell patient.xml
シェルの使い方はman xmllintで確認してください。
いよいよ患者氏名を取得します。
$ xmllint --xpath "/xmlio2/patientinfores/Patient_Information/WholeName/text()" patient.xml |nkf -w80 --numchar-input
何故か結果がUnicode文字参照で返ってくるため、nkfコマンドでUTF-8に変換しています。nkfコマンドはjma-receiptがセットアップされている環境であればインストールされているはずです。
2016年07月05日
この記事へのトラックバックURL
http://blog.sakura.ne.jp/tb/175951346
※ブログオーナーが承認したトラックバックのみ表示されます。
この記事へのトラックバック
http://blog.sakura.ne.jp/tb/175951346
※ブログオーナーが承認したトラックバックのみ表示されます。
この記事へのトラックバック
https://imgur.com/tuUm8Nt
https://imgur.com/29LaPMw
https://imgur.com/sgyvBu6
https://imgur.com/L0GRFqY
https://imgur.com/ZB7IBPA
https://imgur.com/gKJmzKA
https://imgur.com/3CwYBIy
https://imgur.com/thqSaTI
https://imgur.com/w4DaeBe
https://imgur.com/sMZeKna
https://imgur.com/pX7hrsM
https://imgur.com/iaCTzrB
https://imgur.com/mL2AJ3E
https://imgur.com/2dJpHPD
https://imgur.com/mKWZs2e
https://imgur.com/CfYL69W
https://imgur.com/Inz75Rr
https://imgur.com/VCSYd10
https://imgur.com/vgDwUNX
https://imgur.com/KGaaC77
https://imgur.com/DeWjLDD
https://imgur.com/IKxmm4l
https://imgur.com/gVBD1An
https://imgur.com/8yNQ9gU
https://imgur.com/SVABHZe
https://imgur.com/1NrPric
https://imgur.com/NxSe9xI
https://imgur.com/26Uupld
https://imgur.com/I8q5mUr
https://imgur.com/8zvQa0u
https://imgur.com/phGD8k1
https://imgur.com/zL0HiOT
https://imgur.com/UXpCArx
https://imgur.com/xzxC3HU
https://imgur.com/jlCbMz0
https://imgur.com/BzgOtN2
https://imgur.com/QDQCNDg
https://imgur.com/pi8QLru
https://imgur.com/UsKdi97
https://imgur.com/flLsBWH
https://imgur.com/3wec0TV
https://imgur.com/ZyFKCcL
https://imgur.com/X6wFEvl
https://imgur.com/hE8h6oV
https://imgur.com/D78jy0P
https://imgur.com/c5uyGBp
https://imgur.com/3vJEp6m
https://imgur.com/xri1R2u
https://imgur.com/BzUBSB6
https://imgur.com/fxUWEK7
https://imgur.com/u4Y3K3v
https://imgur.com/KAkFXPD
https://imgur.com/x3CfYE7
https://imgur.com/1Zbg1eX
https://imgur.com/Fd34OcO
https://imgur.com/Q7r1CsV
https://imgur.com/aLWwhiZ
https://imgur.com/tgcEpQQ
https://imgur.com/1uRsGe1
https://imgur.com/ONfB3YB
https://imgur.com/uLHOIlJ