Ejemplo n.º 1
0
def upload_drive_api(upload_type):
    file = request.files['file']

    if not allowed_file(file.filename):
        return error_response('invalid file')

    if upload_type not in valid_types:
        return error_response('invalid file type')

    f = LocalFiles(file=file.read())
    file_path = f.save()

    try:
        # upload file to drive
        cloud_file_path = Drive().upload(file_path=file_path,
                                         folder_id=folder_id,
                                         share=True)
        # delete file from local directory
        f.delete()
        # create patient account
        uuid = Patient.create_new()
        # add file url to patient file dict
        obj = {"uuid": uuid, "type": upload_type, "url": cloud_file_path}
        # if patient UUID is valid, add file it
        if not Patient.add_file(**obj):
            return error_response('uuid invalid')

        return success_response(uuid)
    except Exception as e:
        return error_response(e)
Ejemplo n.º 2
0
def insert_profile():
    if request.method == 'POST':
        json = request.form.to_dict(flat=True)
        result = check_json(
            json,
            ['name', 'email', 'specialty', 'password', 'keywords', 'genes'])

        if result:
            return error_response("missing {}".format(result))

        office_db = Office()

        json['office_id'] = office_db.unique_id()
        json['password'] = encrypt(json['password'])
        json['keyword_genes'] = ast.literal_eval(json['genes'])

        #remove key/value from json before insertion
        del json['genes']
        del json['keywords']

        # TODO: check if email exists

        office_db.insert(json)

        return success_response(json['office_id'])
Ejemplo n.º 3
0
def search_genes():
	keyword = request.args.get('keyword', default='', type=str)
	limit = request.args.get('limit', default=100, type=int)

	try:
		result = Gene().search(unquote(keyword), limit)
		return success_response(result)
	except Exception as e:
		return error_response(e)
Ejemplo n.º 4
0
def handle_report(report_id):
    report_db_init = DB(collection='reports')

    query = {"report_id": report_id}

    if request.method == 'GET':
        try:
            report_dict = report_db_init.search_db_one(query)
            if report_dict:
                return success_response(report_dict)
            else:
                return error_response('none')
        except Exception as e:
            return error_response(e)

    if request.method == 'DELETE':
        try:
            report_db_init.delete_one(query)
            return success_response('ok')
        except Exception as e:
            print(e)
            return error_response(e)
Ejemplo n.º 5
0
def profile_handler():
	if request.method == 'POST':
		json = request.form.to_dict(flat=True)
		result = check_json(json, ['name', 'email', 'provider_name', 'provider_email', 'url'])

		if result:
			return error_response("missing {}".format(result))

		User().add(json)
		mailer = Mailer()

		html = 'Name: {} \n Email: {} \n Provider: {} \n Provider Email: {}'.format(json['name'], json['email'], json['provider_name'], json['provider_email'])
		mailer.sendMail(html=html, toaddr="*****@*****.**", subject="Meports: User provider request")

		mailer.sendProviderEmail(provider_name=json['provider_name'], provider_email=json['provider_email'], client_name=json['name'], url=json['url'], client_email=json['email'])

		return success_response('ok')
Ejemplo n.º 6
0
def generate_report():
    # get office param
    office_id = request.args.get('office', default=None, type=str)
    source = request.args.get('source', default=None, type=str)

    mag = 3

    # if office param not passed use a test office_id
    if office_id is None:
        office_id = 'c4e482f6-e21f-11e8-9ada-d20785d6bfad'

    if source is None:
        return error_response('no source supplied')

    # load file - if error then return such
    # TODO: parser for other genome file types ( ancestry, etc. )
    file = request.files['file']
    report_id = REPORT_ID().generate()

    temp_file_path = "{}/misc/tmp/{}".format(appConfig['ROOT_PATH'], report_id)
    file.save(temp_file_path)
    genome_file = REPORT_FILE(file=temp_file_path, source=source).load()

    if not genome_file:
        return error_response('invalid file')

    # insert report ID if file parsed
    REPORT_ID().insert(report_id)
    report_build = REPORT_BUILD(genome_file=genome_file, mag=mag)

    master_response_list = []

    office = Office(office_id=office_id)
    office_query = office.find_one()
    filters = office.get_genes_and_keywords(query=office_query)

    for filter in filters:
        genes_list = filter['gene']
        db_base_query = report_build.return_snps_from_genes(
            genes_list=genes_list)
        master_response_list += report_build.generate_report(
            db_base_query, keyword=filter['keyword'])

    report = {}
    report['report_dict'] = report_build.uniquify(master_response_list)
    report['timestamp'] = time()
    report['report_id'] = report_id

    report['office'] = {
        "id": office_query['office_id'],
        "name": office_query['name'],
        "email": office_query['email']
    }

    session['report_id'] = report_id

    os.remove(temp_file_path)

    DB(collection='reports').update(query={"report_id": report_id},
                                    updated_dict=report)

    return success_response(report['report_id'])
Ejemplo n.º 7
0
def intake_submit_api(patient_uuid):
    json = request.json

    result = check_json(json, ['name', 'email', 'phone'])
    if result:
        return error_response("missing {}".format(result))