in functions/source/preprocess/preprocess.py [0:0]
def lambda_handler(event, context):
'''
Recieves event, by getting triggered with
the upload of the excell file from storage gateway
sends individual patient file and
uploads to source-csv and patient plots to the clabsi bucket .
----------
fieldname : Event
AWS Lambda uses this parameter to pass in event data to the handler.
This parameter is usually of the Python dict type.
It can also be list, str, int, float, or NoneType type.
When you invoke your function,
you determine the content and structure of the event.
When an AWS service invokes your function,
the event structure varies by service.
For details, see Using AWS Lambda with other services.
fieldname: context
AWS Lambda uses this parameter to
provide runtime information to your handler
Returns
-------
Sagemaker labeling job status description
'''
print(context)
s3_client = boto3.client('s3')
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
obj = s3_client.get_object(Bucket=bucket, Key=key)
dataframe_patients, dataframe_temperature = preprocess(obj)
try:
for patient in dataframe_patients['mrn'].unique():
data = dataframe_patients[dataframe_patients['mrn']
== patient].copy()
data.sort_values(
['collection_dt_tm'], inplace=True, ascending=True)
data.reset_index(inplace=True)
data.drop('index', axis=1, inplace=True)
temperature = dataframe_temperature[
dataframe_temperature['mrn'] == patient].copy()
temperature.sort_values(
['collection_dt_tm'], inplace=True, ascending=True)
temperature.reset_index(inplace=True)
temperature.drop('index', axis=1, inplace=True)
# Generate timeline plot
plot_timeline(data, patient)
# Generate IWP plots, one per each collection date
for plot_index in data.index:
generate_iwp_plot(data, temperature, plot_index, patient)
# Generate the CSV file to trigger job creation
write_dataframe_to_csv_on_s3(
data,
f'{os.environ["patient_folder"]}/{patient}.csv',
patient_processed)
except Exception as error:
print(error)
raise error
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')}