in lambda/src/gather_symptom_bot.py [0:0]
def report_symptom(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')
confirmation_status = helper.get_attribute(current_intent, 'confirmationStatus')
symptom = slots.get(SLOT_SYMPTOM_ONE, None)
body_part = slots.get(SLOT_BODY_PART, None)
modifier = slots.get(SLOT_BODY_PART_MODIFIER, None)
intensity = slots.get(SLOT_PAIN_LEVEL, None)
unknown_symptoms = helper.get_list_from_session(session_attributes, UNKNOWN_SYMPTOM_ATTR)
if confirmation_status == helper.ConfirmationStatus.NONE.value:
if helper.is_validation_request(intent_request):
return validate_symptom_input(intent_name, session_attributes, slot_details, slots)
elif confirmation_status == helper.ConfirmationStatus.DENIED.value:
# deny could be for intensity level or for symptoms
if symptom == unknown_symptoms[-1]:
unknown_symptoms.pop()
session_attributes[UNKNOWN_SYMPTOM_ATTR] = json.dumps(unknown_symptoms)
slots = {}
return helper.elicit_slot(session_attributes, intent_name, slots, SLOT_SYMPTOM_ONE,
msg_strings.get('AFTER_SYMPTOM_DENY'))
msg = ''
# after confirming the first symptom, say sorry to hear to show sympathy. However, only say this once per session
if not helper.get_attribute(session_attributes, 'alreadySaidSorry'):
if symptom in unknown_symptoms:
msg += 'Sorry to hear that. '
else:
msg += 'Sorry to hear that you ' + find_descriptor_for_symptom(symptom) + ". "
session_attributes['alreadySaidSorry'] = 'true'
if symptom in intensity_symptom:
# gather pain level
if not intensity:
msg += msg_strings.get('RATE_PAIN_PROMPT')
return helper.elicit_slot(session_attributes, intent_name, slots, SLOT_PAIN_LEVEL, msg)
elif int(intensity) >= INTENSITY_THRESHOLD:
user = helper.lookup_user(session_attributes)
local_time_reported = get_current_time_for_user(user)
symptom_reporter.severe_symptom_report(user, local_time_reported, body_part, intensity)
msg += f'We will notify your medical provider of your {symptom}. '
else:
msg += f"Got it. That's a {intensity} out of 10. "
symptom_obj = {'symptom': symptom}
if body_part:
symptom_obj['bodyPart'] = body_part
if modifier:
symptom_obj['modifier'] = modifier
if intensity:
symptom_obj['intensity'] = int(intensity)
helper.append_session_attr(session_attributes, SYMPTOM_ATTR, symptom_obj)
msg += msg_strings.get('ADDITIONAL_SYMPTOM_QUERY')
return helper.elicit_intent(session_attributes, message_content=msg)