Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdoel committed Oct 8, 2024
1 parent 0e06aa1 commit e8c5937
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
31 changes: 20 additions & 11 deletions email_listmode.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
{
"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,
"required": true,
"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": [
{
Expand All @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions email_radreads.json
Original file line number Diff line number Diff line change
@@ -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#",
Expand All @@ -11,15 +11,15 @@
"mounts": [],
"inputs": [
{
"name": "PROJECTID",
"name": "project-id",
"description": "Project ID",
"type": "string",
"user-settable": false,
"required": true,
"replacement-key": "#PROJECTID#"
},
{
"name": "EMAILLIST",
"name": "email-list",
"description": "Comma separated list of email addresses",
"type": "string",
"user-settable": true,
Expand All @@ -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": [
{
Expand All @@ -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
}
Expand Down
35 changes: 31 additions & 4 deletions src/drc_containers/email_listmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
)


Expand Down

0 comments on commit e8c5937

Please sign in to comment.