in LambdaFunction/index.py [0:0]
def getMedHelp(intent_request):
"""
Retrieve Medication Information for a given patient
"""
logger.info('intent request: {}'.format(intent_request))
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
patientid = output_session_attributes['patientid'] if output_session_attributes['patientid'] is not None else {}
res = fhirclient.get_meds(patientid)
logger.debug(res)
if res['status']==200:
if type(res['response'])==str:
outputtext = res['response']
else:
outputtext = 'I have found the following medications and instructions for you. '
for med in res["response"]:
outputtext += med['medicationReference'] + '. '
if 'dosage' in med and 'patientInstruction' in med['dosage'][0]:
outputtext += 'The dosage for this is the following... ' + med['dosage'][0]['patientInstruction']
else:
outputtext += 'I did not find a dosage for this medication. '
else:
outputtext = 'I do not have any medication for you.'
return close(
output_session_attributes,
'Fulfilled',
{
'contentType': 'PlainText',
'content': outputtext
}
)