From 27032e1876373f9b519275bffbca117f2c96ca1f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 13 Jul 2022 01:27:00 +0300 Subject: Implement study creation Enable the creation of the new study, and redirect appropriately with the new study id. --- qc_app/dbinsert.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py index 18bc7c2..4fbd0d3 100644 --- a/qc_app/dbinsert.py +++ b/qc_app/dbinsert.py @@ -1,6 +1,7 @@ "Handle inserting data into the database" import os import json +import datetime from functools import reduce import requests @@ -149,9 +150,29 @@ def create_study(): "Create a new study (ProbeFreeze)." form = request.form try: + assert form.get("genechipid"), "platform" assert form.get("studyname"), "study name" assert form.get("inbredsetid"), "group" assert form.get("tissueid"), "type/tissue" + + with database_connection() as conn: + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT MAX(Id) AS last_id FROM ProbeFreeze") + new_studyid = cursor.fetchone()["last_id"] + 1 + values = ( + new_studyid, new_studyid, form["genechipid"], + form["tissueid"], form["studyname"], + form.get("studyfullname", ""), + form.get("studyshortname", ""), + datetime.datetime.now().date().strftime("%Y-%m-%d"), + form["inbredsetid"]) + query = ( + "INSERT INTO ProbeFreeze() " + "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)") + cursor.execute(query, values) + return redirect( + url_for("dbinsert.select_dataset", studyid=new_studyid), + code=307) except AssertionError as aserr: flash(f"Missing data: {aserr.args[0]}", "alert-error") return redirect(url_for("dbinsert.select_study"), code=307) -- cgit v1.2.3