Это старая версия документа!
Есть у нас рентген аппарат у которого в xml файле написана кодировка ISO-8859-5, а русские символы в Windows-1251. Изменим тег с кодировкой и конвертируем кириkлицу в латиницу с помощью python и отправим это все дело в ORTHANC.
ОСТОРОЖНО ! ГОВНОКОД !
# -*- coding: utf-8 -*-
import glob
import subprocess
import os
import signal
import fileinput
import sys
import time
import transliterate - https://gist.github.com/ledovsky/6398962
reload(sys)
sys.setdefaultencoding('utf-8')
path="/mnt/data/raid1/sendDCM/"
for filepath in glob.iglob(path+'*.[dD][cC][mM]'):
a=filepath
b=a.split('/')[5]
c=subprocess.Popen("dcm2xml +M +Wb " + filepath + " "+ path + b + ".xml", shell=True)
c.communicate()
def replaceAll(file,searchExp,replaceExp):
for line in fileinput.input(file, inplace=1):
if searchExp in line:
line = line.replace(searchExp,replaceExp)
sys.stdout.write(line)
replaceAll(filepath + ".xml","ISO-8859-5","WINDOWS-1251")
fullpathxml = path + b +'.xml'
import xml.etree.ElementTree as ET
tree = ET.parse(fullpathxml)
PatientName=tree.findall('data-set/element[@name="PatientName"]')[0].text
BodyPE=tree.findall('data-set/element[@name="BodyPartExamined"]')[0].text
if BodyPE:
BodyPE=BodyPE
else:
BodyPE="Не заполнено"
ViewPos=tree.findall('data-set/element[@name="ViewPosition"]')[0].text
if ViewPos:
ViewPos=ViewPos
else:
ViewPos="Не заполнено"
PatientNameTrans= transliterate.transliterate(PatientName)
BodyPETrans= transliterate.transliterate(BodyPE)
ViewPosTrans= transliterate.transliterate(ViewPos)
PatientNameClean=tree.findall('data-set/element[@name="PatientName"]')[0].text = PatientNameTrans
BodyPEClean=tree.findall('data-set/element[@name="BodyPartExamined"]')[0].text = BodyPETrans
ViewPosClean=tree.findall('data-set/element[@name="ViewPosition"]')[0].text = ViewPosTrans
tree.write(fullpathxml)
d=subprocess.Popen("xml2dcm -f "+path + b + ".xml "+ path + b +".mod", shell=True)
time.sleep(5)
e=subprocess.Popen("dcmsend -nuc +ma orthanc.corp.local 4242 "+ path + b +".mod", shell=True)
time.sleep(5)
e.communicate()
os.remove(filepath)
for xmlpath in glob.iglob(os.path.join(path, '*.xml')):
os.remove(xmlpath)
for modpath in glob.iglob(os.path.join(path, '*.mod')):