def test_dicom_store_instance_from_gcs(self): # Store DICOM files to a empty DICOM store from a GCS bucket, # then check if the store metadata match. input_dict_store = {} input_dict_store['project_id'] = self.project input_dict_store['region'] = REGION input_dict_store['dataset_id'] = DATA_SET_ID input_dict_store['dicom_store_id'] = self.temp_dicom_store expected_output = [True] * NUM_INSTANCE with self.test_pipeline as p: gcs_path = DICOM_FILES_PATH + "/io_test_files/*" results = (p | fileio.MatchFiles(gcs_path) | fileio.ReadMatches() | UploadToDicomStore(input_dict_store, 'fileio') | beam.Map(lambda x: x['success'])) assert_that(results, equal_to(expected_output), label='store first assert') # Check the metadata using client result, status_code = DicomApiHttpClient().qido_search( self.project, REGION, DATA_SET_ID, self.temp_dicom_store, 'instances') self.assertEqual(status_code, 200) # List comparison based on different version of python self.assertCountEqual(result, self.expected_output_all_metadata)
def __init__(self, buffer_size=8, max_workers=5, client=None, credential=None): """Initializes DicomSearch. Args: buffer_size: # type: Int. Size of the request buffer. max_workers: # type: Int. Maximum number of threads a worker can create. If it is set to one, all the request will be processed sequentially in a worker. client: # type: object. If it is specified, all the Api calls will made by this client instead of the default one (DicomApiHttpClient). credential: # type: Google credential object, if it is specified, the Http client will use it to create sessions instead of the default. """ self.buffer_size = buffer_size self.max_workers = max_workers self.client = client or DicomApiHttpClient() self.credential = credential
def make_request(self, dicom_file): # Send file to DICOM store and records the results. project_id = self.destination_dict['project_id'] region = self.destination_dict['region'] dataset_id = self.destination_dict['dataset_id'] dicom_store_id = self.destination_dict['dicom_store_id'] # Feed the dicom file into store client if self.client: _, status_code = self.client.dicomweb_store_instance( project_id, region, dataset_id, dicom_store_id, dicom_file, self.credential) else: _, status_code = DicomApiHttpClient().dicomweb_store_instance( project_id, region, dataset_id, dicom_store_id, dicom_file, self.credential) out = {} out['status'] = status_code out['success'] = (status_code == 200) return out