获取dicom信息并推送数据

#! /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()
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值