It was exactly where I went, I analyzed it using pydicom, and I managed to store it the way I wanted, but to recover the data it was complicated, I even tried to recover it through the API-SELF…
from io import BytesIO
from pydicom import dcmread, dcmwrite
from pydicom.filebase import DicomFileLike
import orthanc
import os
import os.path
import sys
def GetPath(uuid, contentType):
series = orthanc.RestApiGet(‘/instances/%s/series’ % (uuid))
study = orthanc.RestApiGet(‘/instances/%s/study’ % (uuid))
ano = series[‘MainDicomTags’][‘SeriesDate’][:4]
mes = series[‘MainDicomTags’][‘SeriesDate’][4:6]
dia = series[‘MainDicomTags’][‘SeriesDate’][6:8]
modalidade = series[‘MainDicomTags’][‘Modality’]
idPaciente = study[‘PatientMainDicomTags’][‘PatientID’]
nomePaciente = study[‘PatientMainDicomTags’][‘PatientName’]
path = ‘C:\storage%s%s%s%s%s - %s’ % (modalidade, ano, mes, dia, idPaciente, nomePaciente)
file = os.path.join(path, uuid)
return file
def OnCreate(uuid, contentType, data):
tags = dcmread(BytesIO(data))
ano = tags.StudyDate[:4]
mes = tags.StudyDate[4:6]
dia = tags.StudyDate[6:8]
modalidade = tags.Modality
idPaciente = tags.PatientID
nomePaciente = tags.PatientName
path = ‘C:\storage%s%s%s%s%s - %s’ % (modalidade, ano, mes, dia, idPaciente, nomePaciente)
try:
os.makedirs(path)
except:
Already existing directory, ignore the error
pass
file = os.path.join(path, ‘%s-%s’ % (contentType,uuid) )
with open(file, ‘wb’) as f:
f.write(data)
def OnRead(uuid, contentType):
with open(GetPath(uuid, contentType), ‘rb’) as f:
return f.read()
def OnRemove(uuid, contentType):
os.remove(GetPath(uuid, contentType))
orthanc.RegisterStorageArea(OnCreate, OnRead, OnRemove)