コード例 #1
0
def nutrientdata():
    if request.method == 'POST':
        obj = request.json
        print json.dumps(obj, indent=4, separators=(',', ': '))
        userid = obj.get("userid")
        appid = obj.get("appid")
        nutrients = obj.get("nutrients")
        date = obj.get("date")
        meal = obj.get("meal")

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

        data = {}
        data['nutrient'] = nutrients

        manager.save_batch(table_nutrient, rowkey, data)

        # print json.dumps(obj, indent=4, separators=(',', ': '))
        return jsonify(success="true")

    if request.method == 'GET':
        userid = request.args.get("userid")
        appid = request.args.get("appid")
        date = request.args.get("date")
        meal = request.args.get("meal")

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

        data = manager.fetch(table_nutrient, rowkey)

        # print data
    return jsonify(data=data)

    return jsonify(success="true")
コード例 #2
0
def pin_code_generate():
    if request.method == 'GET':
        appid = request.args.get("appid")
        userid = request.args.get("userid")
        email = request.args.get("email")

        # generate pin code here
        while True:
            rand = np.random.randint(100000, 999999, 1)[0]
            pin_code = str(rand)

            rowkey = appid + "_" + pin_code
            data = manager.fetch(table_pin_code, rowkey)

            if data is None:
                break

        # save to profile data
        data1 = {}
        data1['profile'] = {'pin_code': pin_code,
                            'role': 'nurse', 'email': email}

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

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

        rowkey2 = appid + "_" + pin_code
        manager.save_batch(table_pin_code, rowkey2, data2)

        return jsonify(success="true", pin_code=pin_code)
コード例 #3
0
def profile():
    if request.method == 'POST':
        obj = request.json

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

        data = {}
        data['profile'] = profile

        # print data

        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)
コード例 #4
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")
コード例 #5
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")
コード例 #6
0
def import_hospital():
    if request.method == 'POST':
        obj = request.json

        hospitals = obj

        for hospitalid, information in hospitals.items():
            data = {}
            data['information'] = information

            rowkey = hospitalid
            manager.save_batch(table_hospital, rowkey, data)

        return jsonify(success="true")
    else:
        return jsonify(success="false")
コード例 #7
0
def profile2():
    if request.method == 'POST':
        obj = request.json

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

        enc_profile = {k.encode('utf8'): 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")
コード例 #8
0
def hospital():
    if request.method == 'POST':
        obj = request.json
        hospitalid = obj.get("hospitalid")
        information = obj.get("information")
        data = {}
        data['information'] = information

        rowkey = hospitalid
        manager.save_batch(table_hospital, rowkey, data)

        return jsonify(success="true")

    elif request.method == 'GET':
        hospitalid = request.args.get("hospitalid")
        rowkey = hospitalid
        column = 'information'
        data = manager.fetch(table_hospital, rowkey, column)

        return jsonify(data=data)
コード例 #9
0
def import_profile():
    if request.method == 'POST':
        obj = request.json

        persons = obj

        for userid_appid, profile in persons.items():
            words = userid_appid.split('_')
            userid = words[0]
            appid = words[1]

            data = {}
            data['profile'] = profile

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

        return jsonify(success="true")
    else:
        return jsonify(success="false")
コード例 #10
0
def import_activity_result_2():
    if request.method == 'POST':
        obj = request.json
        activity_results = obj

        for userid_appid_date_time, activity_result in activity_results.items():
            words = userid_appid_date_time.split('_')
            userid = words[0]
            appid = words[1]
            date = words[2]
            time = words[3]

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

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

            manager.save_batch(table_activity_results_1, rowkey, data)
        return jsonify(success="true", data=data)
    else:
        return jsonify(success="false")
コード例 #11
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")
コード例 #12
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")
コード例 #13
0
def import_surgery():
    if request.method == 'POST':
        obj = request.json

        surgeries = obj

        for userid_hospitalid_date_time, information in surgeries.items():
            words = userid_hospitalid_date_time.split('_')
            userid = words[0]
            hospitalid = words[1]
            date = words[2]
            time = words[3]

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

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

            manager.save_batch(table_surgery, rowkey, data)

        return jsonify(success="true")
    else:
        return jsonify(success="false")
コード例 #14
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")