text stringlengths 0 828 |
|---|
:param message: Response message |
:param content_type: Pika BasicProperties content_type value |
:param headers: Message header properties |
:param mandatory: The mandatory flag |
:param immediate: The immediate flag |
:returns: Boolean corresponding to the success of publishing |
:rtype: bool |
"""""" |
logger.debug(""Publishing message"") |
try: |
self._connect() |
return self._do_publish(mandatory=mandatory, |
immediate=immediate, |
content_type=content_type, |
headers=headers, |
message=message) |
except pika.exceptions.AMQPConnectionError: |
logger.error(""AMQPConnectionError occurred. Message not published."") |
raise PublishMessageError |
except NackError: |
# raised when a message published in publisher-acknowledgments mode |
# is returned via `Basic.Return` followed by `Basic.Ack`. |
logger.error(""NackError occurred. Message not published."") |
raise PublishMessageError |
except UnroutableError: |
# raised when a message published in publisher-acknowledgments |
# mode is returned via `Basic.Return` followed by `Basic.Ack`. |
logger.error(""UnroutableError occurred. Message not published."") |
raise PublishMessageError |
except Exception: |
logger.exception(""Unknown exception occurred. Message not published."") |
raise PublishMessageError" |
4668,"def visit(folder, provenance_id, step_name, previous_step_id=None, config=None, db_url=None, is_organised=True): |
""""""Record all files from a folder into the database. |
Note: |
If a file has been copied from a previous processing step without any transformation, it will be detected and |
marked in the DB. The type of file will be detected and stored in the DB (NIFTI, DICOM, ...). If a files |
(e.g. a DICOM file) contains some meta-data, those will be stored in the DB. |
Arguments: |
:param folder: folder path. |
:param provenance_id: provenance label. |
:param step_name: Name of the processing step that produced the folder to visit. |
:param previous_step_id: (optional) previous processing step ID. If not defined, we assume this is the first |
processing step. |
:param config: List of flags: |
- boost: (optional) When enabled, we consider that all the files from a same folder share the same meta-data. |
When enabled, the processing is (about 2 times) faster. This option is enabled by default. |
- session_id_by_patient: Rarely, a data set might use study IDs which are unique by patient (not for the whole |
study). |
E.g.: LREN data. In such a case, you have to enable this flag. This will use PatientID + StudyID as a session |
ID. |
- visit_id_in_patient_id: Rarely, a data set might mix patient IDs and visit IDs. E.g. : LREN data. In such a |
case, you have to enable this flag. This will try to split PatientID into VisitID and PatientID. |
- visit_id_from_path: Enable this flag to get the visit ID from the folder hierarchy instead of DICOM meta-data |
(e.g. can be useful for PPMI). |
- repetition_from_path: Enable this flag to get the repetition ID from the folder hierarchy instead of DICOM |
meta-data (e.g. can be useful for PPMI). |
:param db_url: (optional) Database URL. If not defined, it looks for an Airflow configuration file. |
:param is_organised: (optional) Disable this flag when scanning a folder that has not been organised yet |
(should only affect nifti files). |
:return: return processing step ID. |
"""""" |
config = config if config else [] |
logging.info(""Visiting %s"", folder) |
logging.info(""-> is_organised=%s"", str(is_organised)) |
logging.info(""-> config=%s"", str(config)) |
logging.info(""Connecting to database..."") |
db_conn = connection.Connection(db_url) |
step_id = _create_step(db_conn, step_name, provenance_id, previous_step_id) |
previous_files_hash = _get_files_hash_from_step(db_conn, previous_step_id) |
checked = dict() |
def process_file(file_path): |
logging.debug(""Processing '%s'"" % file_path) |
file_type = _find_type(file_path) |
if ""DICOM"" == file_type: |
is_copy = _hash_file(file_path) in previous_files_hash |
leaf_folder = os.path.split(file_path)[0] |
if leaf_folder not in checked or 'boost' not in config: |
ret = dicom_import.dicom2db(file_path, file_type, is_copy, step_id, db_conn, |
'session_id_by_patient' in config, 'visit_id_in_patient_id' in config, |
'visit_id_in_patient_id' in config, 'repetition_from_path' in config) |
try: |
checked[leaf_folder] = ret['repetition_id'] |
except KeyError: |
# TODO: Remove it when dicom2db will be more stable |
logging.warning(""Cannot find repetition ID !"") |
else: |
dicom_import.extract_dicom( |
file_path, file_type, is_copy, checked[leaf_folder], step_id) |
elif ""NIFTI"" == file_type and is_organised: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.