Mercurial > hg > orthanc-book
annotate Sphinx/source/plugins/python/worklist.py @ 789:2f70f622059b
added odbc tip
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 24 Nov 2021 15:30:29 +0100 |
parents | 4e9dc26a5cb9 |
children | 01fa632daae9 |
rev | line source |
---|---|
700
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 import json |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 import orthanc |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 import os |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Path to the directory containing the DICOM worklists |
763 | 6 # https://hg.orthanc-server.com/orthanc/file/Orthanc-1.9.7/OrthancServer/Plugins/Samples/ModalityWorklists/WorklistsDatabase |
700
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 WORKLIST_DIR = '/tmp/WorklistsDatabase' |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 def OnWorklist(answers, query, issuerAet, calledAet): |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 print('Received incoming C-FIND worklist request from %s:' % issuerAet) |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # Get a memory buffer containing the DICOM instance |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 dicom = query.WorklistGetDicomQuery() |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # Get the DICOM tags in the JSON format from the binary buffer |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 jsonTags = json.loads(orthanc.DicomBufferToJson( |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 dicom, orthanc.DicomToJsonFormat.SHORT, orthanc.DicomToJsonFlags.NONE, 0)) |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 orthanc.LogWarning('C-FIND worklist request to be handled in Python: %s' % |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 json.dumps(jsonTags, indent = 4, sort_keys = True)) |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 # Loop over the available DICOM worklists |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 for path in os.listdir(WORKLIST_DIR): |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 if os.path.splitext(path) [1] == '.wl': |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 with open(os.path.join(WORKLIST_DIR, path), 'rb') as f: |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 content = f.read() |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 # Test whether the query matches the current worklist |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 if query.WorklistIsMatch(content): |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 orthanc.LogWarning('Matching worklist: %s' % path) |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 answers.WorklistAddAnswer(query, content) |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
56a06ca9ec20
Handling worklist SCP requests in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 orthanc.RegisterWorklistCallback(OnWorklist) |