annotate OrthancServer/Resources/Samples/Lua/OnStableStudy.lua @ 5128:ede035d48b8e

merge
author Alain Mazy <am@osimis.io>
date Mon, 19 Dec 2022 20:00:21 +0100
parents d25f4c0fa160
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1457
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 function Initialize()
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 print('Number of stored studies at initialization: ' ..
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 table.getn(ParseJson(RestApiGet('/studies'))))
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 end
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 function Finalize()
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 print('Number of stored studies at finalization: ' ..
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 table.getn(ParseJson(RestApiGet('/studies'))))
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 end
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 function OnStoredInstance(instanceId, tags, metadata)
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 patient = ParseJson(RestApiGet('/instances/' .. instanceId .. '/patient'))
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 print('Received an instance for patient: ' ..
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 patient['MainDicomTags']['PatientID'] .. ' - ' ..
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 patient['MainDicomTags']['PatientName'])
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 end
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 function OnStableStudy(studyId, tags, metadata)
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 if (metadata['ModifiedFrom'] == nil and
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 metadata['AnonymizedFrom'] == nil) then
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 print('This study is now stable: ' .. studyId)
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 -- The tags to be replaced
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 local replace = {}
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 replace['StudyDescription'] = 'Modified study'
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 replace['StationName'] = 'My Medical Device'
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 replace['0031-1020'] = 'Some private tag'
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 -- The tags to be removed
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 local remove = { 'MilitaryRank' }
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 -- The modification command
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 local command = {}
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 command['Remove'] = remove
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 command['Replace'] = replace
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
1458
1d109322f5d3 comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
41 -- Modify the entire study in one single call
1457
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 local m = RestApiPost('/studies/' .. studyId .. '/modify',
2249
38c7bf2e10f6 updated samples to set keepStrings=ture when calling DumpJson() to access the Orthanc API
Alain Mazy <alain@mazy.be>
parents: 1458
diff changeset
43 DumpJson(command, true))
1457
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 print('Modified study: ' .. m)
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 end
6a9daad345c1 OnStableStudy.lua sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 end