#! /usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'ken'
import requests
import os
import time
import pydicom
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class LinYing:
def __init__(self, path, push_url, notify_url):
self.path = path
self.push_url = push_url
self.notify_url = notify_url
self.file_path_list = []
def get_dir_file(self):
for file in os.listdir(self.path):
series_path = os.path.join(self.path, file)
if os.path.isdir(series_path):
file_name_list = os.listdir(series_path)
for file_name in file_name_list:
file_path = os.path.join(series_path, file_name)
self.file_path_list.append(file_path)
def get_dicom_value(self):
dcmData = pydicom.read_file(self.file_path_list[0])
# dcmVale = []
#
# dcmAccessionNumber = dcmData.get_item([0x008, 0x0050])
# dcmPatientId = dcmData.get_item([0x010, 0x0020])
# # print(dcmAccessionNumber.value.decode())
# dcmVale.append(dcmAccessionNumber.value.decode())
# # print(dcmPatientId.value.decode())
# dcmVale.append(dcmPatientId.value.decode())
return dcmData
def push_data(self):
for file_path in self.file_path_list:
try:
page = requests.post(self.push_url, verify=False, files={'file': open(file_path, 'rb')})
print(file_path)
print(page.status_code)
except:
print("Connection refused by the server..")
print("Let me sleep for 5 seconds")
print("ZZzzzz...")
time.sleep(5)
print("Was a nice sleep, now let me continue...")
continue
# requests.post(self.push_url, verify=False, files={'file': open(file_path, 'rb')})
def notifyM(self):
dcm_set = self.get_dicom_value()
ss = requests.post(self.notify_url, verify=False, json={
"uorbit_site": "https://imagepvs.union-laboratory.com",
"unitedimaging_site": "http://api.united-imaging.com",
"patientid": (str((dcm_set.get_item([0x010, 0x0020]).value).decode()).strip()),
"accessnumber": (str((dcm_set.get_item([0x008, 0x0050]).value).decode()).strip()),
# "patientid": 'P00100334',
# "accessnumber": 'ZYCT201807090441',
"status": 320,
"msg": "upload finished"
})
# def __call__(self, *args, **kwargs):
# self.get_dir_file()
#
# self.push_data()
# self.notifyM()
if __name__ == "__main__":
push_url = 'https://linying.united-imaging.com:9001/linying/upload'
notify_url = 'https://linying.united-imaging.com:9001/linying/notify'
file_dir = r"/Users/zrg/Desktop/工作/新建文件夹 (3)/20190926/ct/1.2.194.0.108707908.20190926145517.170.16155.4450509"
ly = LinYing(file_dir, push_url, notify_url)
# 获取dicom数据
ly.get_dir_file()
# 推送dicom数据
ly.push_data()
# 发送推送数据成功的消息
ly.notifyM()
获取dicom信息并推送数据
最新推荐文章于 2023-07-13 15:40:36 发布