class DicomParser: """Class for parsing DICOM files.""" def __init__(self, **kwargs): """Initialize with url to DICOM server.""" self.server = DicomServer(**kwargs) def get_info(self, patient): """Return main DICOM tags from Orthanc.""" url = os.path.join('patients', patient) return self.server.api(url)['MainDicomTags'] def radiation_total_dose(self, patient_id): """Calculate total dose in Gy of treatment plan.""" # TODO: write method here return
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Thu May 10 22:21:15 2018 @author: Michal """ """Extract data form DICOM server and store in mongo.""" import os from pymongo import MongoClient from dicom_server import DicomServer from dicom_parser import DicomParser # Instantiate server object server = DicomServer() # Check that DICOM server is working print 'Checking if server is working...' print 'Should get response 200, got response {}'.format(server.echo()) # Search DICOM server using DicomServer methods patients = server.api('patients') # Store data in mongo # Create connection to database client = MongoClient(os.getenv('MONGODB_URL')) db = client.get_default_database()
"""Extract data form DICOM server and store in mongo.""" import os from pymongo import MongoClient from dicom_server import DicomServer from dicom_parser import DicomParser # Instantiate server object server = DicomServer() # Check that DICOM server is working print 'Checking if server is working...' print 'Should get response 200, got response {}'.format(server.echo()) # Search DICOM server using DicomServer methods # Find total number of patients patients = server.api('patients') print 'There are {} patients'.format(len(patients)) # Get the DICOM PatientID associated with each Orthanc patient id for patient in patients: url = os.path.join('patients', patient) patient_id = server.api(url)['MainDicomTags']['PatientID'] print 'Orthanc patient id: {}, DICOM PatientID: {}'.format( patient, patient_id) # Find total number of male patients query = {'PatientSex': 'M'} print 'Searching for: {}'.format(query) male_patients = server.find(query, level='Patient') print 'There are {} male patients'.format(len(male_patients))
def __init__(self, **kwargs): """Initialize with url to DICOM server.""" self.server = DicomServer(**kwargs)
class DicomParser: """Class for parsing DICOM files.""" def __init__(self, **kwargs): """Initialize with url to DICOM server.""" self.server = DicomServer(**kwargs) def get_info(self, patient): """Return main DICOM tags from Orthanc.""" url = os.path.join('patients', patient) return self.server.api(url)['MainDicomTags'] def radiation_total_dose(self, patient): """Calculate total dose in Gy of treatment plan.""" url = os.path.join('patients', patient) PatientID = self.server.api(url)['MainDicomTags']['PatientID'] studies = self.server.api(url)['Studies'] BeamDoses = 0 for study in studies: series = [] flat_series_list = [] studies_url = os.path.join('studies',study) series.append(self.server.api(studies_url)['Series']) for sublist in series: for item in sublist: flat_series_list.append(item) for a_series in flat_series_list: instances = [] flat_instances_list = [] series_url = os.path.join('series',a_series) if self.server.api(series_url)['MainDicomTags']['Modality'] == 'RTPLAN': instances.append(self.server.api(series_url)['Instances']) for sublist in instances: for item in sublist: flat_instances_list.append(item) for instance in flat_instances_list: instance_tags = self.server.api(os.path.join('instances', instance, 'simplified-tags')) beam_sequences = [] if 'FractionGroupSequence' in instance_tags.keys(): for i in instance_tags['FractionGroupSequence']: beam_sequences.append(i['ReferencedBeamSequence']) beam_seqs_flattened = [] for j in beam_sequences: for item in j: beam_seqs_flattened.append(item) for k in beam_seqs_flattened: BeamDoses = BeamDoses + float(k['BeamDose']) return {'PatientID':PatientID,'radiation_total_dose':BeamDoses}
"""Delete all patients store in DICOM server.""" import os import requests from dicom_server import DicomServer # Instantiate server object server = DicomServer() # Get patient hashes patients = server.api('patients') for patient in patients: url = os.path.join(os.getenv('DICOM_URL'), 'patients', patient) r = requests.delete(url) if r.status_code == 200: print 'Successfully deleted: {}'.format(patient) else: print 'Failed to delete: {}'.format(patient) print 'Status code: {}'.format(r.status_code)