Exemplo n.º 1
0
def pat_search(text):
    api = Env.ALGOLIA_API()
    admin = Env.ALGOLIA_ADMIN()
    client = SearchClient.create(api, admin)
    index = client.init_index('patients')
    index.set_settings({"customRanking": ["desc(followers)"]})
    index.set_settings({
        "searchableAttributes": [
            "firstName",
            "lastName",
            "phone",
            "email",
            "id"
        ]
    })

    # Res is all hits of Patients with matching
    res = index.search(text)
    hits = res['hits']
    pats_return = []
    for h in hits:
        pat_obj = {
            "id": h['id'],
            "firstName": h['firstName'],
            "lastName": h['lastName'],
            "email": h['email'],
            "phone": h['phone'],
            "profilePicture": h['profilePicture']
        }
        pats_return.append(pat_obj)
    return pats_return
Exemplo n.º 2
0
def add_hcp(hcp):
    api = Env.ALGOLIA_API()
    admin = Env.ALGOLIA_ADMIN()
    client = SearchClient.create(api, admin)
    index = client.init_index('hcps')
    res = {
        "id": hcp.id,
        "firstName": hcp.firstName,
        "lastName": hcp.lastName,
        "phone": hcp.phone,
        "email": hcp.email,
        "title": hcp.title,
        "specialty": hcp.specialty,
        "profilePicture": hcp.profilePicture
    }
    with open('js.json', 'w') as fp:
        json.dump(res, fp)

    batch = json.load(open('js.json'))
    fp.close()
    try:
        index.save_object(batch, {'autoGenerateObjectIDIfNotExist': True})
    except Exception as e:
        print(f'Error: {e}')
    return 0
Exemplo n.º 3
0
def get_heroku_app():
    global app
    heroku_conn = heroku3.from_key(Env.HEROKU_API_KEY())
    app = heroku_conn.apps()['upmed-api']
Exemplo n.º 4
0
    'encrypted_cert.enc')
dec_cert_path = join(
    os.path.dirname(
        os.path.realpath(__file__)),
    'decrypted_cert.json')

"""
Read encrypted file
"""
with open(enc_cert_path, mode="rb") as file:
    encrypted_cert = file.read()

"""
Decrypt and write decrypted file
"""
decrypted_cert = decrypt(Env.FIREBASE_PRIVATE_KEY(), encrypted_cert)
with open(dec_cert_path, mode="wb") as file:
    file.write(decrypted_cert)

"""
Ensure decrypted JSON certificate is deleted on exit
"""


def delete_decrypt_on_exit():
    os.remove(dec_cert_path)


atexit.register(delete_decrypt_on_exit)

"""
Exemplo n.º 5
0
def pat_edit_profile(db, pid, post_data):
    try:
        patient_resp = db.document(str(pid)).get().to_dict()
        patient = Patient(
            id=patient_resp['id'],
            firstName=post_data.get('firstName'),
            lastName=post_data.get('lastName'),
            phone=post_data.get('phone'),
            email=post_data.get('email'),
            dateOfBirth=patient_resp['dateOfBirth'],
            sex=patient_resp['sex'],
            profilePicture=patient_resp['profilePicture'],
            height=post_data.get('height'),
            weight=post_data.get('weight'),
            drinker=post_data.get('drinker'),
            smoker=post_data.get('smoker'),
            calendar=patient_resp['calendar'],
            doctors=patient_resp['doctors'],
            health=patient_resp['health']
        )
        try:
            patient.profilePicture = post_data.get('profilePicture')
        except KeyError:
            patient.profilePicture = patient_resp['profilePicture']

        api = Env.ALGOLIA_API()
        admin = Env.ALGOLIA_ADMIN()
        client = SearchClient.create(api, admin)
        index = client.init_index('patients')
        index.set_settings({"customRanking": ["desc(followers)"]})
        index.set_settings({
            "searchableAttributes": [
                "firstName",
                "lastName",
                "phone",
                "email",
                "id"
            ]
        })

        # Res is all hits of Patients with matching
        res = index.search(patient.id)
        hits = res['hits'][0]
        # print(hits)
        h = hits['objectID']
        # print(h)
        # Delete stale entry

        print(f'objid: {h}')
        index.delete_object(h)
        add_pat(patient)
        db.document(patient.id).set({
            "id": patient.id,
            "firstName": patient.firstName,
            "lastName": patient.lastName,
            "phone": patient.phone,
            "email": patient.email,
            "dateOfBirth": patient.dateOfBirth,
            "sex": patient.sex,
            "profilePicture": patient.profilePicture,
            "height": patient.height,
            "weight": patient.weight,
            "drinker": patient.drinker,
            "smoker": patient.smoker,
            "calendar": patient.calendar,
            "health": patient.health,
            "doctors": patient.doctors
        })
        res = {
            "Success": True
        }
        return res
    except Exception:
        res = {
            "Success": False
        }
        return res
Exemplo n.º 6
0
def hcp_edit_profile(db, hid, post_data):
    hcp_resp = db.document(str(hid)).get().to_dict()
    schedule = make_week()
    hcp = HCP(
        id=post_data.get('id'),
        firstName=post_data.get('firstName'),
        lastName=post_data.get('lastName'),
        phone=str(post_data.get('phone')),
        email=post_data.get('email'),
        specialty='',
        profilePicture='',
        calendar=hcp_resp['calendar'],
        title='',
        patients=hcp_resp['patients'],
        hours=schedule
    )
    # Replace in Algolia
    # 1. Get objects from ALgolia
    api = Env.ALGOLIA_API()
    admin = Env.ALGOLIA_ADMIN()
    client = SearchClient.create(api, admin)
    index = client.init_index('hcps')
    index.set_settings({"customRanking": ["desc(followers)"]})
    index.set_settings(
        {"searchableAttributes": ["firstName", "lastName", "phone",
                                  "email", "id", "title", "specialty"]})
    res = index.search(hcp.id)

    # Res is all hits of Patients with matching
    hits = res['hits'][0]
    h = hits['objectID']
    # Delete stale entry
    index.delete_object(h)

    try:
        hcp.specialty = post_data.get('specialty')
    except Exception as e:
        hcp.specialty = ''
    try:
        hcp.title = post_data.get('title')
    except Exception as e:
        hcp.title = ''
    try:
        hcp.profilePicture = post_data.get('profilePicture')
    except Exception as e:
        hcp.profilePicture = default_pic
    if hcp.profilePicture is None:
        hcp.profilePicture = default_pic

    try:
        newsched = post_data.get('hours')
        if int(newsched['sunday']['startTime']) == \
                -1 and int(newsched['sunday']['endTime']) == -1:
            hcp.hours.sunday.startTime = -1
            hcp.hours.sunday.endTime = -1
        elif 0 <= int(newsched['sunday']['startTime']) \
                <= int(newsched['sunday']['endTime']):
            hcp.hours.sunday.startTime = int(
                newsched['sunday']['startTime'])
            hcp.hours.sunday.endTime = int(
                newsched['sunday']['endTime'])

        if int(newsched['monday']['startTime']) == \
                -1 and int(newsched['monday']['endTime']) == -1:
            hcp.hours.monday.startTime = -1
            hcp.hours.monday.endTime = -1
        elif 0 <= int(newsched['monday']['startTime']) \
                <= int(newsched['monday']['endTime']):
            hcp.hours.monday.startTime = int(
                newsched['monday']['startTime'])
            hcp.hours.monday.endTime = int(
                newsched['monday']['endTime'])

        if int(newsched['tuesday']['startTime']) == \
                -1 and int(newsched['tuesday']['endTime']) == -1:
            hcp.hours.tuesday.startTime = -1
            hcp.hours.tuesday.endTime = -1
        elif 0 <= int(newsched['tuesday']['startTime']) \
                <= int(newsched['tuesday']['endTime']):
            hcp.hours.tuesday.startTime = int(
                newsched['tuesday']['startTime'])
            hcp.hours.tuesday.endTime = int(
                newsched['tuesday']['endTime'])

        if int(newsched['wednesday']['startTime']) == \
                -1 and int(newsched['wednesday']['endTime']) == -1:
            hcp.hours.wednesday.startTime = -1
            hcp.hours.wednesday.endTime = -1
        elif 0 <= int(newsched['wednesday']['startTime']) \
                <= int(newsched['wednesday']['endTime']):
            hcp.hours.wednesday.startTime = int(
                newsched['wednesday']['startTime'])
            hcp.hours.wednesday.endTime = int(
                newsched['wednesday']['endTime'])

        if int(newsched['thursday']['startTime']) == \
                -1 and int(newsched['thursday']['endTime']) == -1:
            hcp.hours.thursday.startTime = -1
            hcp.hours.thursday.endTime = -1
        elif 0 <= int(newsched['thursday']['startTime']) \
                <= int(newsched['thursday']['endTime']):
            hcp.hours.thursday.startTime = int(
                newsched['thursday']['startTime'])
            hcp.hours.thursday.endTime = int(
                newsched['thursday']['endTime'])

        if int(newsched['friday']['startTime']) == \
                -1 and int(newsched['friday']['endTime']) == -1:
            hcp.hours.friday.startTime = -1
            hcp.hours.friday.endTime = -1
        elif 0 <= int(newsched['friday']['startTime']) \
                <= int(newsched['friday']['endTime']):
            hcp.hours.friday.startTime = int(
                newsched['friday']['startTime'])
            hcp.hours.friday.endTime = int(
                newsched['friday']['endTime'])

        if int(newsched['saturday']['startTime']) == \
                -1 and int(newsched['saturday']['endTime']) == -1:
            hcp.hours.sunday.saturday = -1
            hcp.hours.sunday.saturday = -1
        elif 0 <= int(newsched['saturday']['startTime']) \
                <= int(newsched['saturday']['endTime']):
            hcp.hours.saturday.startTime = int(
                newsched['saturday']['startTime'])
            hcp.hours.saturday.endTime = int(
                newsched['saturday']['endTime'])

        hours = []
        time = []
        time.append(hcp.hours.sunday.startTime)
        time.append(hcp.hours.sunday.endTime)
        hours.append(str(time))
        time[0] = hcp.hours.monday.startTime
        time[1] = hcp.hours.monday.endTime
        hours.append(str(time))
        time[0] = hcp.hours.tuesday.startTime
        time[1] = hcp.hours.tuesday.endTime
        hours.append(str(time))
        time[0] = hcp.hours.wednesday.startTime
        time[1] = hcp.hours.wednesday.endTime
        hours.append(str(time))
        time[0] = hcp.hours.thursday.startTime
        time[1] = hcp.hours.thursday.endTime
        hours.append(str(time))
        time[0] = hcp.hours.friday.startTime
        time[1] = hcp.hours.friday.endTime
        hours.append(str(time))
        time[0] = hcp.hours.saturday.startTime
        time[1] = hcp.hours.saturday.endTime
        hours.append(str(time))
    except Exception as e:
        print(e)
        hcp.hours = make_week()

    # Insert updated entry
    add_hcp(hcp)

    if hid == hcp.id:
        db.document(hcp.id).set({
            "id": hcp.id,
            "firstName": hcp.firstName,
            "lastName": hcp.lastName,
            "phone": hcp.phone,
            "email": hcp.email,
            "profilePicture": hcp.profilePicture,
            "calendar": hcp.calendar,
            "specialty": hcp.specialty,
            "title": hcp.title,
            "hours": hours,
            "patients": hcp.patients,
        })
    else:
        response_object = {
            'Success': False,
            'message': "Invalid Token"
        }
        return response_object
    response_object = {
        "Success": True
    }
    return response_object
Exemplo n.º 7
0
import os
from flask import Flask
from flask_cors import CORS

from sys import path
from os.path import join, dirname

path.append(join(dirname(__file__), '..'))

from src.util.env import Env  # noqa
from src.api import api_endpoints  # noqa
"""
Create app and register blueprints
"""
app = Flask(__name__)
if Env.USE_CORS():
    CORS(app)
api_endpoints.bind_to_app(app)
app.app_context().push()


@app.route('/')
def hello_world():
    target = os.environ.get('TARGET', 'World')
    return 'Hello {}!\n'.format(target)


if __name__ == "__main__":
    app.run(port=Env.PORT())