Mercurial > hg > orthanc
annotate Resources/Samples/Lua/ModifyInstanceWithSequence.lua @ 1699:8ca0e89798b2
"/modify" can insert/modify sequences
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Oct 2015 13:31:22 +0200 |
parents | |
children | 38c7bf2e10f6 |
rev | line source |
---|---|
1699
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 -- Answer to: |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 -- https://groups.google.com/d/msg/orthanc-users/0ymHe1cDBCQ/YfD0NoOTn0wJ |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 -- Applicable starting with Orthanc 0.9.5 |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 function OnStoredInstance(instanceId, tags, metadata, origin) |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 -- Do not modify twice the same file |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 if origin['RequestOrigin'] ~= 'Lua' then |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 local replace = {} |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 replace['0010,1002'] = {} |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 replace['0010,1002'][1] = {} |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 replace['0010,1002'][1]['PatientID'] = 'Hello' |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 replace['0010,1002'][2] = {} |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 replace['0010,1002'][2]['PatientID'] = 'World' |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 local request = {} |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 request['Replace'] = replace |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 -- Create the modified instance |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 local modified = RestApiPost('/instances/' .. instanceId .. '/modify', |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 DumpJson(request)) |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 -- Upload the modified instance to the Orthanc store |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 RestApiPost('/instances/', modified) |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 -- Delete the original instance |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 RestApiDelete('/instances/' .. instanceId) |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 end |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 end |