in lambda/src/outreach_scanner.py [0:0]
def schedule_outreach_for_participant(participant_id, start_date_str, end_date_str, surveys):
user = user_profile.lookup_user_by_id(participant_id)
user_local_tz = pytz.timezone(user.timezone)
today = datetime.now(tz=timezone.utc).astimezone(user_local_tz)
if not check_trial_start_and_enddate(participant_id, user_local_tz, start_date_str, end_date_str, today):
return
if already_scheduled_outreach(participant_id, today):
return
surveys_to_take = []
for survey_name in surveys:
# TODO: filter out surveys that are not daily and not due today
survey = surveys[survey_name]
surveys_to_take.append(survey)
surveys_to_take.sort(key=lambda x: x['Priority'])
initialize_survey_to_complete(participant_id, today, surveys_to_take)
initial_outreach_wait_time = OUTREACH_BEFORE_TEXT_USER_DELAY # seconds
schedule_outreach_input = {
'UserId': participant_id,
'TimeZone': user.timezone,
'Date': format_date_to_str(today),
'wait': {
'mode': 'SECONDS',
'seconds': initial_outreach_wait_time
}
}
execution_arn = None
if OUTREACH_WORKFLOW:
response = sfn_client.start_execution(
stateMachineArn=OUTREACH_WORKFLOW,
input=json.dumps(schedule_outreach_input)
)
execution_arn = response['executionArn']
logger.info(f'scheduled outreach: {execution_arn}')
with DDBUpdateBuilder(
key={'Patient_ID': participant_id, 'Report_Date': format_date_to_str(today)},
table_name=SURVEY_COMPLETION_TABLE) as ddb_update_builder:
if execution_arn:
ddb_update_builder.update_attr('Execution_ID', execution_arn)