output writing

Added the function or writing to output file real time instead of buffering
This commit is contained in:
2025-05-14 16:57:34 +00:00
parent 1d5092ed60
commit 59823679b7

View File

@@ -14,7 +14,13 @@ import ast
# === Constants and Logging Setup === # === Constants and Logging Setup ===
LOG_FILE = "dicom_query.log" LOG_FILE = "dicom_query.log"
CONFIG_FILE = "config.txt" CONFIG_FILE = "config.txt"
LOG_LEVELS = {"DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL} LOG_LEVELS = {
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL
}
logging.basicConfig( logging.basicConfig(
filename=LOG_FILE, filename=LOG_FILE,
@@ -195,15 +201,19 @@ class ConfigDialog:
except Exception: except Exception:
mod_string = str(mod_raw).strip() mod_string = str(mod_raw).strip()
writer.writerow([ try:
str(getattr(identifier, 'PatientID', '')).strip(), writer.writerow([
str(getattr(identifier, 'PatientName', '')).strip(), str(getattr(identifier, 'PatientID', '')).strip(),
str(getattr(identifier, 'AccessionNumber', '')).strip(), str(getattr(identifier, 'PatientName', '')).strip(),
str(getattr(identifier, 'StudyDate', '')).strip(), str(getattr(identifier, 'AccessionNumber', '')).strip(),
str(getattr(identifier, 'StudyInstanceUID', '')).strip(), str(getattr(identifier, 'StudyDate', '')).strip(),
mod_string, str(getattr(identifier, 'StudyInstanceUID', '')).strip(),
str(getattr(identifier, 'NumberOfStudyRelatedInstances', '')).strip() mod_string,
]) str(getattr(identifier, 'NumberOfStudyRelatedInstances', '')).strip()
])
f.flush()
except Exception as e:
logging.exception("Error writing to output file.")
elif status: elif status:
logging.debug("C-FIND response: 0x%04X", status.Status) logging.debug("C-FIND response: 0x%04X", status.Status)
except Exception as e: except Exception as e: