Exemplo n.º 1
0
def activity_result_1():
    if request.method == 'POST':
        obj = request.json
        userid = obj.get("userid")
        appid = obj.get("appid")
        date = obj.get("date")
        time = obj.get("time")
        results = obj.get("results")

        results_json = json.dumps(results, ensure_ascii=False, encoding='utf8')

        rowkey = userid + "_" + appid + "_" + date + "_" + time

        # data = {}
        # data['activity_result_1'] = results_json

        # manager.save_batch(table_activity_results_1, rowkey, results_json)
        manager.insert_data(table_activity_results_1, rowkey,
                            'activity_result_1', 'result', results_json)

        return jsonify(success="true")

    elif request.method == 'GET':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        begin = request.args.get("start_date")  # "2017-09-11"
        end = request.args.get("end_date")  # 2017-09-15

        # Get data

        end = dt.datetime.strptime(end, "%Y-%m-%d")
        end = end + dt.timedelta(days=1)

        start_row = base64.b64encode("{}_{}_{}_".format(userid, appid, begin))
        end_row = base64.b64encode("{}_{}_{}_".format(userid, appid, end))

        desc = manager.fetch_from_with_row_id(
            table_activity_results_1, start_row, end_row)

        desc_list = list(desc)

        for dl in desc_list:
            dl.values()[0]['activity_result_1']['result'] = json.loads(
                dl.values()[0]['activity_result_1']['result'].replace("\'", '"'))

        return jsonify(data=desc_list)

    elif request.method == 'DELETE':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        date = request.args.get("date")
        time = request.args.get("time")

        rowkey = userid + "_" + appid + "_" + date + "_" + time

        manager.delete_row(table_activity_results_1, rowkey)

        return jsonify(success="true")
Exemplo n.º 2
0
def medicine():
    if request.method == 'POST':
        obj = request.json

        userid = obj.get("userid")
        appid = obj.get("appid")
        medicine = obj.get("medicine")
        med_id = obj.get("medId")
        desc = service.get_medicine_bykey(med_id)
        side_effect = desc.get("side_effect")
        title = desc.get("title")

        rowkey = userid + "_" + appid + "_" + med_id

        data = {}
        data['medicine'] = medicine
        data['medicine']['title'] = title
        data['medicine']['side_effect'] = side_effect

        manager.save_batch(table_medicines, rowkey, data)

        # print json.dumps(obj, indent=4, separators=(',', ': '))

        return jsonify(success="true")
    elif request.method == 'GET':  # get all current use medicine
        userid = request.args.get("userid")
        appid = request.args.get("appid")

        start_row = base64.b64encode("{}_{}".format(userid, appid))
        # start_row <= key < end_row //must have end_row use x to ended the key
        end_row = base64.b64encode("{}_{}x".format(userid, appid))

        desc = manager.fetch_from(table_medicines, start_row, end_row)
        desc_list = list(desc)
        desc_value = []
        for key in desc_list:
            for x in key:
                desc_value.append(key.get(x))

        schedule = service.get_medicine_schedule(desc_list)

        return jsonify(data=list(schedule.items()), desc=desc_value)

    elif request.method == 'DELETE':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        med_id = request.args.get('medId')

        rowkey = userid + "_" + appid + "_" + med_id

        manager.delete_row(table_medicines, rowkey)

        return jsonify(success="true")
Exemplo n.º 3
0
def six_mins_walk():
    if request.method == 'POST':
        obj = request.json

        userid = obj.get("userid")
        appid = obj.get("appid")
        date = obj.get("date")
        time = obj.get("time")
        results = obj.get("results")

        results_json = json.dumps(results, ensure_ascii=False, encoding='utf8')

        rowkey = userid + "_" + appid + "_" + date + "_" + time

        manager.insert_data(table_6minswalk, rowkey,
                            '6minswalk', 'result', results_json)

        return jsonify(success="true")

        rowkey = userid + "_" + appid + "_" + date + "_" + time

    elif request.method == 'GET':
        userid = request.args.get("userid")
        appid = request.args.get("appid")

        # Get data
        start_row = base64.b64encode("{}_{}_".format(userid, appid))

        desc = manager.fetch_from_with_row_id(
            table_6minswalk, start_row)

        desc_list = list(desc)

        for dl in desc_list:
            dl.values()[0]['6minswalk']['result'] = json.loads(
                dl.values()[0]['6minswalk']['result'].replace("\'", '"'))

        return jsonify(data=desc_list)

    elif request.method == 'DELETE':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        date = request.args.get("date")
        time = request.args.get("time")

        rowkey = userid + "_" + appid + "_" + date + "_" + time

        manager.delete_row(table_6minswalk, rowkey)

        return jsonify(success="true")
Exemplo n.º 4
0
def activity_result_2():
    if request.method == 'POST':
        obj = request.json
        userid = obj.get("userid")
        appid = obj.get("appid")
        date = obj.get("date")
        time = obj.get("time")
        results = json.dumps(obj.get("results"), ensure_ascii=False)

        rowkey = userid + "_" + appid + "_" + date + "_" + time

        data = {}
        data['activity_result_2'] = results

        manager.save_batch(table_activity_results_2, rowkey, data)

        return jsonify(success="true")

    elif request.method == 'GET':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        begin = request.args.get("start_date")  # "2017-09-11"
        end = request.args.get("end_date")  # 2017-09-15

        end = dt.datetime.strptime(end, "%Y-%m-%d")
        end = end + dt.timedelta(days=1)

        start_row = base64.b64encode("{}_{}_{}_".format(userid, appid, begin))
        end_row = base64.b64encode("{}_{}_{}_".format(userid, appid, end))

        desc = manager.fetch_from_with_row_id(
            table_activity_results_2, start_row, end_row)

        desc_list = list(desc)

        return jsonify(data=desc_list)

    elif request.method == 'DELETE':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        date = request.args.get("date")
        time = request.args.get("time")

        rowkey = userid + "_" + appid + "_" + date + "_" + time

        manager.delete_row(table_activity_results_2, rowkey)

        return jsonify(success="true")
Exemplo n.º 5
0
def profile():
    if request.method == 'POST':
        obj = request.json

        userid = obj.get("userid")
        appid = obj.get("appid")
        profile = obj.get("profile")

        enc_profile = {str(k).encode('utf8'): str(v).encode('utf8')
                       for k, v in profile.items()}

        data = {
            "profile": enc_profile
        }

        rowkey = userid + "_" + appid
        manager.save_batch(table_information, rowkey, data)

        return jsonify(success="true")

    elif request.method == 'GET':
        userid = request.args.get("userid")
        appid = request.args.get("appid")

        rowkey = userid + "_" + appid
        column = 'profile'

        data = manager.fetch(table_information, rowkey, column)

        return jsonify(data=data)

    elif request.method == 'DELETE':
        userid = request.args.get("userid")
        appid = request.args.get("appid")

        rowkey = userid + "_" + appid

        manager.delete_row(table_information, rowkey)

        return jsonify(success="true")
Exemplo n.º 6
0
def surgery():
    if request.method == 'POST':
        obj = request.json
        userid = obj.get("userid")
        hospitalid = obj.get("hospitalid")
        date = obj.get("date")
        time = obj.get("time")
        information = obj.get("information")

        data = {}
        data['information'] = information

        rowkey = userid + "_" + hospitalid + "_" + date + "_" + time
        manager.save_batch(table_surgery, rowkey, data)

        return jsonify(success="true")

    elif request.method == 'GET':
        userid = request.args.get("userid")

        start_row = base64.b64encode("{}_".format(userid))

        desc = manager.fetch_from(table_surgery, start_row)

        desc_list = list(desc)

        return jsonify(data=desc_list)

    elif request.method == 'DELETE':
        userid = request.args.get("userid")
        hospitalid = request.args.get("hospitalid")
        date = request.args.get("date")
        time = request.args.get("time")

        rowkey = userid + "_" + hospitalid + "_" + date + "_" + time

        manager.delete_row(table_surgery, rowkey)

        return jsonify(success="true")
Exemplo n.º 7
0
def patient_code_generate():
    if request.method == 'GET':
        appid = request.args.get("appid")
        userid = request.args.get("userid")
        email = request.args.get("email")
        admit_date = request.args.get("admit_date")

        # generate patient code here
        while True:
            rand = np.random.randint(1000, 9999, 1)[0]
            patient_code = 'PATIENT' + str(rand)

            rowkey = appid + "_" + patient_code
            data = manager.fetch(table_patient_code, rowkey)

            if data is None:
                break

        # save to profile data
        data1 = {}
        data1['profile'] = {'patient_code': patient_code,
                            'role': 'patient', 'email': email, 'level': 0}

        rowkey1 = userid + "_" + appid
        manager.save_batch(table_information, rowkey1, data1)

        # save to patient code data
        data2 = {}
        data2['patient_code'] = {'userid': userid,
                                 'email': email, 'admit_date': admit_date}

        rowkey2 = appid + "_" + patient_code
        manager.save_batch(table_patient_code, rowkey2, data2)

        return jsonify(success="true", patient_code=patient_code)

    elif request.method == 'POST':
        obj = request.json
        appid = obj.get("appid")
        patient_code = obj.get("patient_code")
        profile = obj.get("profile")

        enc_profile = {k.encode('utf8'): v.encode('utf8')
                       for k, v in profile.items()}

        data = {}
        data['patient_code'] = enc_profile

        rowkey = appid + "_" + patient_code
        manager.save_batch(table_patient_code, rowkey, data)

        return jsonify(success="true")

    elif request.method == 'DELETE':
        appid = request.args.get("appid")
        patient_code = request.args.get('patient_code')

        rowkey = appid + "_" + patient_code

        manager.delete_row(table_patient_code, rowkey)

        return jsonify(success="true")