Example #1
0
 def handle(self, event, context):
     try:
         id = event["queryStringParameters"][DATASTORE_COLUMN_PATIENT_ID] if DATASTORE_COLUMN_PATIENT_ID in event["queryStringParameters"] else None  
         result = self.getItems(id)
         return sendResponse(200, result)
     except Exception as e:
         return sendResponse(500, {'message':  "An unknown error has occurred. Please try again."})
Example #2
0
    def handle(self, event, context):
        try:
            sessionId = event['queryStringParameters'][
                DATASTORE_COLUMN_SESSION_ID].strip(
                ) if DATASTORE_COLUMN_SESSION_ID in event[
                    'queryStringParameters'] else None
            if sessionId is None or sessionId[:2] != 's-':
                return sendResponse(
                    400, {
                        'message':
                        DATASTORE_COLUMN_SESSION_ID + " has incorrect format"
                    })

            bucket = os.environ['BUCKET_NAME']
            comprehend_key = self.getKeyName(sessionId, 'comprehend', 'json')
            transcribe_key = self.getKeyName(sessionId, 'transcribe', 'txt')
            client = boto3.client('s3', region_name=os.environ['AWS_REGION'])
            comprehend_result = client.get_object(Bucket=bucket,
                                                  Key=comprehend_key)
            transcribe_result = client.get_object(Bucket=bucket,
                                                  Key=transcribe_key)
            result = {
                'comprehend':
                (comprehend_result['Body'].read()).decode("utf-8"),
                'transcribe':
                (transcribe_result['Body'].read()).decode("utf-8")
            }

            return sendResponse(200, result)
        except Exception as e:
            print(str(e))
            return sendResponse(500, {
                'message':
                "An unknown error has occurred. Please try again."
            })
Example #3
0
 def handle(self, event, context):
     try:
         name = event["queryStringParameters"][
             DATASTORE_COLUMN_PATIENT_NAME] if DATASTORE_COLUMN_PATIENT_NAME in event[
                 "queryStringParameters"] else None
         if name is None or name.strip() == '':
             return sendResponse(
                 400, {
                     'message':
                     DATASTORE_COLUMN_PATIENT_NAME + ' should not be empty.'
                 })
         id = self.putItem(name.strip())
         result = {DATASTORE_COLUMN_PATIENT_ID: id}
         return sendResponse(200, result)
     except Exception as e:
         return sendResponse(500, {
             'message':
             "An unknown error has occurred. Please try again."
         })
    def handle(self, event, context):
        try:
            PatientId = event["queryStringParameters"][DATASTORE_COLUMN_PATIENT_ID].strip() if DATASTORE_COLUMN_PATIENT_ID in event["queryStringParameters"] else None
            HealthCareProfessionalId = event["queryStringParameters"][DATASTORE_COLUMN_HEALTH_CARE_PROFESSSIONAL_ID].strip() if DATASTORE_COLUMN_HEALTH_CARE_PROFESSSIONAL_ID in event["queryStringParameters"] else None
            SessionName = event["queryStringParameters"][DATASTORE_COLUMN_SESSION_NAME].strip() if DATASTORE_COLUMN_SESSION_NAME in event["queryStringParameters"] else None
            SessionId = event["queryStringParameters"][DATASTORE_COLUMN_SESSION_ID].strip() if DATASTORE_COLUMN_SESSION_ID in event["queryStringParameters"] else None
            TimeStampStart = event["queryStringParameters"][DATASTORE_COLUMN_TIMESTAMP_START] if DATASTORE_COLUMN_TIMESTAMP_START in event["queryStringParameters"] else None
            TimeStampEnd= event["queryStringParameters"][DATASTORE_COLUMN_TIMESTAMP_END] if DATASTORE_COLUMN_TIMESTAMP_END in event["queryStringParameters"] else None
            TranscribeS3Path = event["queryStringParameters"][DATASTORE_COLUMN_TRANSCRIBE_S3_PATH] if DATASTORE_COLUMN_TRANSCRIBE_S3_PATH in event["queryStringParameters"] else None
            ComprehendS3Path = event["queryStringParameters"][DATASTORE_COLUMN_COMPREHEND_S3_PATH] if DATASTORE_COLUMN_COMPREHEND_S3_PATH in event["queryStringParameters"] else None

            if PatientId is None or PatientId == '' or PatientId[:2] != 'p-':
                return sendResponse(400, {'message':  DATASTORE_COLUMN_PATIENT_ID + " has incorrect format"})
            if HealthCareProfessionalId is None or HealthCareProfessionalId == '' or HealthCareProfessionalId[:2] != 'h-':
                return sendResponse(400, {'message':  DATASTORE_COLUMN_HEALTH_CARE_PROFESSSIONAL_ID + " has incorrect format"})
            if SessionName is None or SessionName == '':
                return sendResponse(400, {'message':  DATASTORE_COLUMN_SESSION_NAME + " should not be empty"})
            if SessionId is None or SessionId == '' or SessionId[:2] != 's-':
                return sendResponse(400, {'message':  DATASTORE_COLUMN_SESSION_ID + " has incorrect format"})

            id = self.putItem(PatientId, HealthCareProfessionalId, SessionName, SessionId, TimeStampStart, TimeStampEnd, TranscribeS3Path, ComprehendS3Path)
            result = {DATASTORE_COLUMN_SESSION_ID : id}
            return sendResponse(200, result)
        except Exception as e:
            print("Unexpected error: %s" % e)
            return sendResponse(500, {'message':  "An unknown error has occurred. Please try again."})
 def handle(self, event, context):
     try:
         targetLanguageCode = event['queryStringParameters'][
             TRANSLATION_TARGET_LANGUAGE_CODE].strip(
             ) if TRANSLATION_TARGET_LANGUAGE_CODE in event[
                 'queryStringParameters'] else ''
         translationSourceText = event['queryStringParameters'][
             TRANSLATION_SOURCE_TEXT].strip(
             ) if TRANSLATION_SOURCE_TEXT in event[
                 'queryStringParameters'] else ''
         if len(targetLanguageCode) == 0 or len(translationSourceText) == 0:
             return sendResponse(
                 400, {
                     'message':
                     TRANSLATION_SOURCE_TEXT + "," +
                     TRANSLATION_TARGET_LANGUAGE_CODE +
                     " parameters cannot be empty"
                 })
         if len(translationSourceText.encode(
                 'utf-8')) > TRANSLATION_TEXT_MAX_UTF8_BYTES_SIZE:
             return sendResponse(
                 400, {
                     'message':
                     "Translation is supported for translationSourceText <"
                     + TRANSLATION_MAX_UTF8_BYTES_SIZE +
                     "bytes. Please split the payload or try in smaller chunks."
                 })
         client = boto3.client('translate',
                               region_name=os.environ['AWS_REGION'])
         translate_result = client.translate_text(
             Text=translationSourceText,
             SourceLanguageCode='en',
             TargetLanguageCode=targetLanguageCode)
         result = {'translate': translate_result}
         return sendResponse(200, result)
     except Exception as e:
         print(str(e))
         if e.response['Error'][
                 'Code'] == 'UnsupportedLanguagePairException':
             return sendResponse(
                 400, {
                     'message':
                     "Unsupported Language Pair Translation. Please try with one of supported target language."
                 })
         if e.response['Error']['Code'] == 'InvalidRequestException':
             return sendResponse(
                 400, {
                     'message':
                     "Invalid request provided. Please ensure try with English input text and supported target language."
                 })
         return sendResponse(500, {
             'message':
             "An unknown error has occurred. Please try again."
         })
Example #6
0
 def handle(self, event, context):
     try:
         PatientId = event["queryStringParameters"][DATASTORE_COLUMN_PATIENT_ID] if DATASTORE_COLUMN_PATIENT_ID in event["queryStringParameters"] else None
         HealthCareProfessionalId = event["queryStringParameters"][DATASTORE_COLUMN_HEALTH_CARE_PROFESSSIONAL_ID] if DATASTORE_COLUMN_HEALTH_CARE_PROFESSSIONAL_ID in event["queryStringParameters"] else None
         SessionId = event["queryStringParameters"][DATASTORE_COLUMN_SESSION_ID].strip() if DATASTORE_COLUMN_SESSION_ID in event["queryStringParameters"] else None
         result = self.getItems(PatientId, HealthCareProfessionalId, SessionId)
         return {
         "isBase64Encoded": False,
         "statusCode": 200,
         'body': json.dumps(result, cls=DecimalEncoder),
         "headers": {
             'Content-Type': 'application/json',
             'Access-Control-Allow-Origin': '*',
             'Access-Control-Allow-Headers': '*',
             'Access-Control-Allow-Methods': 'GET,POST,OPTIONS'
             }
         }
     except Exception as e:
         return sendResponse(500, {'message':  "An unknown error has occurred. Please try again."})