Beispiel #1
0
def createPatient():
    #requirements: table exists -> name (optional), email (optional)

    #getting name and email from app
    #sample input argument
    #{
    #	"name" : "leela",
    #	"email" : "*****@*****.**"
    #}

    data = request.data
    dataDirt = json.loads(data)

    patient_name = dataDirt['name']
    patient_email = dataDirt['email']

    #creating the cursor
    cur = db.cursor()

    try:  #attempt to create a new patient profile
        cur.execute(
            "INSERT INTO patient(date_created, name, email) VALUES (NOW(), %s, %s)",
            (patient_name, patient_email))
    except Exception, e:
        return "error creating patient"  #something went wrong with adding to the table
Beispiel #2
0
def addMemory(patientId):
    cur = db.cursor()

    # sample input
    # {
    #	"keywords": [
    #		"a",
    #		"b"
    #	],
    #	"message": "keys on fridge!"
    # }

    data = request.data
    dataDirt = json.loads(data)

    #follow the JSON I gave out!
    message = dataDirt['message']

    try:
        #insert memory into memory table
        cur.execute(
            "INSERT INTO memory (patient_id, date_created, passage) VALUES (%s, NOW(), %s)",
            (patientId, message))
        memory_last_id = cur.lastrowid
        for key in dataDirt['keywords']:
            print(key)
            #insert key words into keyword table
            cur.execute(
                "INSERT INTO keys_db (memory_id, word) VALUES (%s, %s)",
                (memory_last_id, key))
            key_last_id = cur.lastrowid
            cur.execute(
                "SELECT * FROM recall_db WHERE word = %s AND patient_id = %s",
                (key, patientId))
            data = cur.fetchall()
            #if this is the first entry
            if len(data) == 0:
                cur.execute(
                    "INSERT INTO recall_db (word, memory_id, patient_id, search_count, store_count) VALUES (%s, %s, %s, %s, %s)",
                    (key, memory_last_id, patientId, 0, 1))
                print("creating first entry")
            #If an entry is already there
            else:
                cur.execute(
                    "SELECT store_count FROM recall_db WHERE word = %s AND patient_id = %s",
                    (key, patientId))
                data = cur.fetchall()
                count = 0
                #iterate the counter
                for row in data:
                    count = str(row[0])
                new_count = int(count) + 1
                cur.execute(
                    "UPDATE recall_db SET store_count = %s WHERE patient_id = %s AND word = %s",
                    (new_count, patientId, key))
    #Error!
    except Exception, e:
        return createErrorResponse("Something went wrong in post of memory.py",
                                   e, 500)
Beispiel #3
0
def PatientMostSearched(patientId):
	cur = db.cursor()
	# 	print(patientId)
	temp = ""
	try:
		cur.execute("SELECT word,MAX(search_count) FROM recall_db where patient_id = %s", (patientId))
	except Exception,e :
		return "Error finding most stored"
Beispiel #4
0
def PatientMemories(patientId):
    cur = db.cursor()

    try:
        cur.execute("SELECT date_created, passage FROM memory WHERE patient_id = %s", patientId)
        data = cur.fetchall()
    except Exception, e:
        return "Error retriving memories"
Beispiel #5
0
def patient_cg(caretakerId,patientId):
    #preconditions table exists -> patient Id, caregiver id

    cur = db.cursor()

    try: #attempting to combine the patient and the caregiver and timestamp
        cur.execute("INSERT INTO patient_cg (care_giver_id, patient_id, time_created) VALUES (%s, %s, NOW())", (caretakerId, patientId))
    except Exception, e:
        return "Error combining"  #if something goes wrong
Beispiel #6
0
def PatientList(caretakerId):
    #preconditions: need Caregiver ID
    cur = db.cursor()

    try: #attempting to info of all patient for a particualr caretaker
        cur.execute("SELECT patient_id FROM patient_cg WHERE care_giver_id = %s", caretakerId)
        data = cur.fetchall()
    except Exception, e:
        return "Error looking"  #if something goes wrong
Beispiel #7
0
def PatientMemories(patientId):
    cur = db.cursor()

    try:
        cur.execute(
            "SELECT date_created, passage FROM memory WHERE patient_id = %s",
            patientId)
        data = cur.fetchall()
    except Exception, e:
        return "Error retriving memories"
Beispiel #8
0
def PatientMostSearched(patientId):
    cur = db.cursor()
    # 	print(patientId)
    temp = ""
    try:
        cur.execute(
            "SELECT word,MAX(search_count) FROM recall_db where patient_id = %s",
            (patientId))
    except Exception, e:
        return "Error finding most stored"
Beispiel #9
0
def patient_cg(caretakerId, patientId):
    #preconditions table exists -> patient Id, caregiver id

    cur = db.cursor()

    try:  #attempting to combine the patient and the caregiver and timestamp
        cur.execute(
            "INSERT INTO patient_cg (care_giver_id, patient_id, time_created) VALUES (%s, %s, NOW())",
            (caretakerId, patientId))
    except Exception, e:
        return "Error combining"  #if something goes wrong
Beispiel #10
0
def Patientinfo( patientId):
    #preconditions: patientId from portal
    cur = db.cursor()

    try:
        cur.execute("SELECT date_created, name, email FROM patient WHERE patient_id = %s", patientId)
        data = cur.fetchone()
    except Exception, e:
        return "Error looking Patientinfo"  #if something goes wrong

	cur.close()
Beispiel #11
0
def PatientList(caretakerId):
    #preconditions: need Caregiver ID
    cur = db.cursor()

    try:  #attempting to info of all patient for a particualr caretaker
        cur.execute(
            "SELECT patient_id FROM patient_cg WHERE care_giver_id = %s",
            caretakerId)
        data = cur.fetchall()
    except Exception, e:
        return "Error looking"  #if something goes wrong
Beispiel #12
0
def Patientinfo(patientId):
    #preconditions: patientId from portal
    cur = db.cursor()

    try:
        cur.execute(
            "SELECT date_created, name, email FROM patient WHERE patient_id = %s",
            patientId)
        data = cur.fetchone()
    except Exception, e:
        return "Error looking Patientinfo"  #if something goes wrong

        cur.close()
Beispiel #13
0
def getMemory(patientId):
	#make sure to include ?search=something when using this
	cur = db.cursor()
	try:
		searchkeys = request.args.getlist("searchkeys")
		
		# search for all rows in recall_db where patientid = patientid and (word = searchkeys[i] OR word = searchkey[i+1])
		format_strings = ','.join(['%s'] * len(searchkeys))		
		cur.execute("select distinct passage from keys_db left join memory using(memory_id) where patient_id = %s and word IN ({0}) order by date_created desc".format(format_strings), (patientId, tuple(searchkeys)))
		rows = cur.fetchall()
		
		memory_list = []
		for row in rows:
			memory_list.append(row[0])
	except Exception, e:
		return createErrorResponse("Problem in the Get function of memory.py", e, 500)
Beispiel #14
0
def addMemory(patientId):
	cur = db.cursor()
	
	# sample input
	# {
	#	"keywords": [
	#		"a",
	#		"b"
	#	],
	#	"message": "keys on fridge!"
	# }
	
	data = request.data
	dataDirt = json.loads(data)

	#follow the JSON I gave out!
	message = dataDirt['message']

	try:
		#insert memory into memory table
		cur.execute("INSERT INTO memory (patient_id, date_created, passage) VALUES (%s, NOW(), %s)", (patientId, message))
		memory_last_id = cur.lastrowid
		for key in dataDirt['keywords']:
			print(key)
			#insert key words into keyword table
			cur.execute("INSERT INTO keys_db (memory_id, word) VALUES (%s, %s)", (memory_last_id, key))
			key_last_id = cur.lastrowid
			cur.execute("SELECT * FROM recall_db WHERE word = %s AND patient_id = %s", (key, patientId))
			data = cur.fetchall()
			#if this is the first entry
			if len(data) == 0:
				cur.execute("INSERT INTO recall_db (word, memory_id, patient_id, search_count, store_count) VALUES (%s, %s, %s, %s, %s)", (key, memory_last_id, patientId, 0, 1))
				print("creating first entry")
			#If an entry is already there
			else:
				cur.execute("SELECT store_count FROM recall_db WHERE word = %s AND patient_id = %s", (key, patientId))
				data = cur.fetchall()
				count = 0
				#iterate the counter
				for row in data:
					 count = str(row[0])
				new_count = int(count) + 1
				cur.execute("UPDATE recall_db SET store_count = %s WHERE patient_id = %s AND word = %s", (new_count, patientId, key))
	#Error!
	except Exception, e:
		return createErrorResponse("Something went wrong in post of memory.py", e, 500)
Beispiel #15
0
def getMemory(patientId):
    #make sure to include ?search=something when using this
    cur = db.cursor()
    try:
        searchkeys = request.args.getlist("searchkeys")

        # search for all rows in recall_db where patientid = patientid and (word = searchkeys[i] OR word = searchkey[i+1])
        format_strings = ','.join(['%s'] * len(searchkeys))
        cur.execute(
            "select distinct passage from keys_db left join memory using(memory_id) where patient_id = %s and word IN ({0}) order by date_created desc"
            .format(format_strings), (patientId, tuple(searchkeys)))
        rows = cur.fetchall()

        memory_list = []
        for row in rows:
            memory_list.append(row[0])
    except Exception, e:
        return createErrorResponse("Problem in the Get function of memory.py",
                                   e, 500)
Beispiel #16
0
def createPatient():
	#requirements: table exists -> name (optional), email (optional)

 	#getting name and email from app
		#sample input argument
			#{
    		#	"name" : "leela",
    		#	"email" : "*****@*****.**"
			#}

	data = request.data
	dataDirt = json.loads(data)

	patient_name = dataDirt['name']
	patient_email = dataDirt['email']


	#creating the cursor
	cur = db.cursor()

	try: #attempt to create a new patient profile
		cur.execute("INSERT INTO patient(date_created, name, email) VALUES (NOW(), %s, %s)", (patient_name, patient_email))
	except Exception, e:
		return "error creating patient"   #something went wrong with adding to the table
Beispiel #17
0
    #sample input argument
    #{
    #    "name" : "zioberg",
    #    "email" : "*****@*****.**"
    #}
    try:
        data = request.data
        dataDirt = json.loads(data)
    except Exception, e:
        return "ERROR, need name & email"

    caregiver_name = dataDirt['name']
    caregiver_email = dataDirt['email']

    #creating the cursor
    cur = db.cursor()

    try:  #attempt to create a new caregiver profile
        cur.execute(
            "INSERT INTO care_giver(date_created, name, email) VALUES (NOW(), %s, %s)",
            (caregiver_name, caregiver_email))
    except Exception, e:
        return "Error creating care_giver"  #if something went wrong with adding to the table

    stored_id = cur.lastrowid
    cur.close()
    db.commit()

    #postconditions: if success then return Caregiver ID
    return jsonify({'caretakerID': stored_id})  #indicating everything was good
Beispiel #18
0
            #sample input argument
                #{
                #    "name" : "zioberg",
                #    "email" : "*****@*****.**"
                #}
        try:
       	    data = request.data
       	    dataDirt = json.loads(data);
        except Exception, e:
            return "ERROR, need name & email"

        caregiver_name = dataDirt['name']
        caregiver_email = dataDirt['email']

    	#creating the cursor
    	cur = db.cursor()

    	try: #attempt to create a new caregiver profile
    		cur.execute("INSERT INTO care_giver(date_created, name, email) VALUES (NOW(), %s, %s)", (caregiver_name, caregiver_email))
    	except Exception, e:
    		return "Error creating care_giver"   #if something went wrong with adding to the table

        stored_id = cur.lastrowid
    	cur.close()
    	db.commit()

    #postconditions: if success then return Caregiver ID
    	return jsonify({'caretakerID':stored_id}) #indicating everything was good

@caretaker_api.route('/<int:caretakerId>/<int:patientId>/', methods=['GET'])
#Function to Pair caregiver and patients (called by Portal)