generated from FNNDSC/python-chrisapp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfdcm.py
65 lines (58 loc) · 1.9 KB
/
pfdcm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
from loguru import logger
import sys
import copy
from collections import ChainMap
import json
LOG = logger.debug
logger_format = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> │ "
"<level>{level: <5}</level> │ "
"<yellow>{name: >28}</yellow>::"
"<cyan>{function: <30}</cyan> @"
"<cyan>{line: <4}</cyan> ║ "
"<level>{message}</level>"
)
logger.remove()
logger.add(sys.stderr, format=logger_format)
def health_check(url: str):
pfdcm_about_api = f'{url}about/'
headers = {'Content-Type': 'application/json', 'accept': 'application/json'}
try:
response = requests.get(pfdcm_about_api, headers=headers)
return response
except Exception as er:
raise Exception("Connection to pfdcm could not be established.")
def retrieve_pacsfiles(directive: dict, url: str, pacs_name: str):
"""
This method uses the async API endpoint of `pfdcm` to send a single 'retrieve' request that in
turn uses `oxidicom` to push and register PACS files to a CUBE instance
"""
pfdcm_dicom_api = f'{url}PACS/thread/pypx/'
headers = {'Content-Type': 'application/json', 'accept': 'application/json'}
body = {
"PACSservice": {
"value": pacs_name
},
"listenerService": {
"value": "default"
},
"PACSdirective": {
"withFeedBack": True,
"then": "retrieve",
"thenArgs": '',
"dblogbasepath": '/home/dicom/log',
"json_response": False
}
}
body["PACSdirective"].update(directive)
LOG(f"request : {body}")
try:
response = requests.post(pfdcm_dicom_api, json=body, headers=headers)
d_response = json.loads(response.text)
if d_response['response']['job']['status']:
return d_response
else:
raise Exception(d_response['message'])
except Exception as er:
LOG(er)