Mercurial > hg > orthanc
annotate Resources/Samples/Lua/CallWebService.lua @ 2313:d19e716b79fa issue-46-anonymization
switch to anonymization according to DICOM 2017c
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2017 22:07:07 +0200 |
parents | 65b1ce7cb84f |
children | 11f8d72f366f |
rev | line source |
---|---|
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 -- This sample shows how to call a remote Web service whenever an |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 -- instance is received by Orthanc. For this sample to work, you have |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 -- to start the "CallWebService.js" script next to this file using |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 -- NodeJs. |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 -- Download and install the JSON module for Lua by Jeffrey Friedl |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 -- http://regex.info/blog/lua/json |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 JSON = (loadstring(HttpGet('http://regex.info/code/JSON.lua'))) () |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 SetHttpCredentials('alice', 'alicePassword') |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 function OnStoredInstance(instanceId, tags, metadata) |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 -- Build the POST body |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 local info = {} |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 info['InstanceID'] = instanceId |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 info['PatientName'] = tags['PatientName'] |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 info['PatientID'] = tags['PatientID'] |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 -- Send the POST request |
2032
65b1ce7cb84f
Replaced "localhost" by "127.0.0.1", as it might impact performance on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1055
diff
changeset
|
20 local answer = HttpPost('http://127.0.0.1:8000/', JSON:encode(info)) |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 -- The answer equals "ERROR" in case of an error |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 print('Web service called, answer received: ' .. answer) |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 end |