def getPatientAuth()

in LambdaFunction/index.py [0:0]


def getPatientAuth(intent_request):
    """
    Authenticate caller and return FHIR STU3 patient ID for the following query
    """
    logger.debug('intent request: {}'.format(intent_request))
    output_session_attributes = intent_request['currentIntent']['slots'] if intent_request['currentIntent']['slots'] is not None else {}
    telecom = intent_request['sessionAttributes']['telecom'] if intent_request['sessionAttributes']['telecom'] is not None else {}
    
    ## format phone number
    telecom = '{0}-{1}-{2}'.format(telecom[-10:-7], telecom[-7:-4], telecom[-4:])
    logger.debug('phone number after tranformation: {}'.format(telecom))
    patientinfo = {
        'birthdate': output_session_attributes['patientBirthday'], 
        'gender': output_session_attributes['patientGender'],
        'telecom': telecom
    }
    r = fhirclient.get_patient(patientinfo)
    output_session_attributes['patientid']=r['response']
    if r['status']==200:
        statusMessage = "Thank you for authenticating"
    else:
        statusMessage = "I'm sorry, I didn't find a patient with that information"
    return close(
        output_session_attributes,
        'Fulfilled',
        {
            'contentType': 'PlainText',
            'content': statusMessage
        }
    )