in lambda/src/medication_diary_bot.py [0:0]
def medication_time(intent_request):
"""
Handler for the medication time intent
:param intent_request: lex intent request
:return:
"""
session_attributes = helper.get_attribute(intent_request, 'sessionAttributes')
current_intent = helper.get_attribute(intent_request, 'currentIntent')
slots = helper.get_attribute(current_intent, 'slots')
slot_details = helper.get_attribute(current_intent, 'slotDetails')
intent_name = helper.get_attribute(current_intent, 'name')
if helper.is_validation_request(intent_request):
return validate_medication_time(intent_name, session_attributes, slot_details, slots)
med_taken_time = slots[SLOT_MED_TIME]
hh = int(med_taken_time.split(':')[0])
mm = int(med_taken_time.split(':')[1])
user = helper.lookup_user(session_attributes)
local_time_reported = get_current_time_for_user(user)
now_with_no_timezone = datetime.now()
med_taken_datetime = now_with_no_timezone.replace(hour=hh, minute=mm, second=0)
local_med_time = pytz.timezone(user.timezone).localize(med_taken_datetime)
# TODO: for production, handle cases when user reported the same info multiple times.
med_diary.log_med(user.uid, time_reported=local_time_reported, med_taken=True, time_taken=local_med_time)
update_survey_completion(user.uid, local_time_reported, BOT_MEDICATION_NAME)
session_attributes['NextBot'] = get_next_survey_bot(user.uid, local_time_reported)
return helper.close(session_attributes, helper.FulfillmentState.FULFILLED,
message_content=msg_strings.get('FINISH_MED_DIARY'))