diff --git a/email_listmode.json b/email_listmode.json index cd6d2ce..43fc548 100644 --- a/email_listmode.json +++ b/email_listmode.json @@ -1,17 +1,17 @@ { "name": "email-listmode", - "description": "Send email with listmode warnings", - "label": "Send email with listmode warnings", - "version": "1.0", + "description": "Send email listing subjects with missing listmode data", + "label": "Listmode email", + "version": "1.1", "schema-version": "1.0", "type": "docker", - "command-line": "email_listmode #PROJECTID# #EMAILLIST#", + "command-line": "email_listmode #PROJECTID# #THRESHOLDDAYS# #EMAILLIST#", "image": "ghcr.io/ucl-mirsg/drc-containers:latest", "override-entrypoint": true, "mounts": [], "inputs": [ { - "name": "PROJECTID", + "name": "project-id", "description": "Project ID", "type": "string", "user-settable": false, @@ -19,20 +19,29 @@ "replacement-key": "#PROJECTID#" }, { - "name": "EMAILLIST", + "name": "email-list", "description": "Comma separated list of email addresses", "type": "string", "user-settable": true, "required": true, "replacement-key": "#EMAILLIST#" + }, + { + "name": "threshold-days", + "description": "Only check sessions created within this number of days", + "type": "number", + "user-settable": true, + "required": true, + "replacement-key": "#THRESHOLDDAYS#", + "default-value": 90 } ], "outputs": [], "xnat": [ { - "name": "project-email-listmode", - "label": "Send email with listmode warnings", - "description": "Send email with listmode warnings", + "name": "email-listmode-project", + "label": "Send listmode email", + "description": "Send email listing subjects with missing listmode data", "contexts": ["xnat:projectData"], "external-inputs": [ { @@ -45,11 +54,11 @@ ], "derived-inputs": [ { - "name": "project-id", + "name": "project-identifier", "type": "string", "derived-from-wrapper-input": "project", "derived-from-xnat-object-property": "id", - "provides-value-for-command-input": "PROJECTID", + "provides-value-for-command-input": "project-id", "user-settable": false, "required": true } diff --git a/email_radreads.json b/email_radreads.json index c18fcea..948eb63 100644 --- a/email_radreads.json +++ b/email_radreads.json @@ -1,8 +1,8 @@ { "name": "email-radreads", "description": "Send email listing sessions without radreads", - "label": "Send email listing sessions without radreads", - "version": "1.0", + "label": "Radreads email", + "version": "1.1", "schema-version": "1.0", "type": "docker", "command-line": "email_radreads #PROJECTID# #EMAILLIST#", @@ -11,7 +11,7 @@ "mounts": [], "inputs": [ { - "name": "PROJECTID", + "name": "project-id", "description": "Project ID", "type": "string", "user-settable": false, @@ -19,7 +19,7 @@ "replacement-key": "#PROJECTID#" }, { - "name": "EMAILLIST", + "name": "email-list", "description": "Comma separated list of email addresses", "type": "string", "user-settable": true, @@ -30,9 +30,9 @@ "outputs": [], "xnat": [ { - "name": "project-email-radreads", - "label": "Send email listing sessions without radreads", - "description": "Send email listing sessions without radreads", + "name": "email-radreads-project", + "label": "Send radreads email", + "description": "Send email listing sessions requiring radreads", "contexts": ["xnat:projectData"], "external-inputs": [ { @@ -45,11 +45,11 @@ ], "derived-inputs": [ { - "name": "project-id", + "name": "project-identifier", "type": "string", "derived-from-wrapper-input": "project", "derived-from-xnat-object-property": "id", - "provides-value-for-command-input": "PROJECTID", + "provides-value-for-command-input": "project-id", "user-settable": false, "required": true } diff --git a/src/drc_containers/email_listmode.py b/src/drc_containers/email_listmode.py index 8d229e4..5c0e838 100644 --- a/src/drc_containers/email_listmode.py +++ b/src/drc_containers/email_listmode.py @@ -95,6 +95,17 @@ def check_session( def get_listmode_issues( pyxnat_interface: Interface, threshold_days: int, project_name: str ) -> set[ListModeRecord]: + """ + + Args: + pyxnat_interface: current pyxnat session + threshold_days: check only sessions created within this number of days + project_name: name of project in which to check sessions + + Returns: + set of ListModeRecords, each describing a session with missing listmode + data + """ session_datatypes = [ "xnat:crSessionData", "xnat:mrSessionData", @@ -156,6 +167,7 @@ def email_listmode( project_name: str, email_subject: str, to_emails: list[str], + threshold_days: int = 90, cc_emails: list[str] = None, bcc_emails: list[str] = None, debug_output: bool = True, @@ -165,6 +177,7 @@ def email_listmode( Args: credentials: XNAT host name and user login details project_name: The project to search for sessions + threshold_days: check only sessions created within this number of days email_subject: subject line of email to_emails: list of email addresses. XNAT will only send emails to addresses which already correspond to XNAT users on the server @@ -178,7 +191,7 @@ def email_listmode( with open_pyxnat_session(credentials=credentials) as xnat_session: # Get list of ListModeRecords sessions_to_report = get_listmode_issues( - pyxnat_interface=xnat_session, threshold_days=90, project_name=project_name + pyxnat_interface=xnat_session, threshold_days=threshold_days, project_name=project_name ) if debug_output: @@ -213,18 +226,32 @@ def email_listmode( def main(): - if len(sys.argv) < 3: + if len(sys.argv) < 4: raise ValueError("No email list specified") + to_emails = sys.argv[3].split(",") + + if len(sys.argv) < 3: + raise ValueError("No threshold days specified") + threshold_days_str = sys.argv[2] + if len(sys.argv) < 2: raise ValueError("No project name specified") + project_name = sys.argv[1] + + try: + threshold_days = int(threshold_days_str) + except ValueError: + raise ValueError("Invalid input for threshold days: " + "{threshold_days_str}") credentials = XnatContainerCredentials() email_listmode( credentials=credentials, - project_name=sys.argv[1], + project_name=project_name, + threshold_days=threshold_days, email_subject="1946 Weekly Listmode Status Check", - to_emails=sys.argv[2].split(","), + to_emails=to_emails, )