def fetch_To_delete():
    if session.get('username'):
        if session.get('usertype') == "rde":
            patientData = {}
            patientid = request.args.get("patientid")
            if patientid:
                cursor.execute(
                    """SELECT (`*`) FROM `patient` WHERE `ws_ssn` LIKE '{}' """
                    .format(patientid))
                patientData = cursor.fetchone()
                #Splitting the address in to Street State and City
                getCompleteAddress = patientData[4].__str__()
                splittedAddress = getCompleteAddress.split(" , ", 2)
                street = splittedAddress[0]
                State = splittedAddress[1]
                city = splittedAddress[2]
                patient = Patient(patientData[0], patientData[2],
                                  patientData[3], patientData[6], street,
                                  State, city)
            else:
                flash("No patient found")
                return redirect("/update_patient")
            form = ShowPatient(obj=patient)
            form.populate_obj(patient)
            if form.validate_on_submit():
                cursor.execute(
                    "DELETE FROM `patient` WHERE `ws_ssn` LIKE '{}' "
                    "".format(patientid))
                conn.commit()
                flash("Patient Deleted Successfully")
                return redirect("/create_patient")
            return render_template("delete_patient.html", form=form)

    return redirect("/login")
Ejemplo n.º 2
0
def insert_data():
    with open(r"resource/test.json", 'r') as load_f:
        load_dict = json.load(load_f)
        cursor = conn.cursor()
        for prov in load_dict:
            cursor.execute(
                'insert into tb_province(provid,provname,state) values(%s,%s,\'1\')',
                [prov["code"], prov["name"]])
            if len(prov["sub"]) > 0:
                for city in prov["sub"]:
                    cursor.execute(
                        'insert into tb_city(cityid,cityname,provid,provname,state) values(%s,%s,%s,%s,\'1\')',
                        [
                            city["code"], city["name"], prov["code"],
                            prov["name"]
                        ])
                    if 'sub' in city and len(city["sub"]) > 0:
                        for country in city["sub"]:
                            cursor.execute(
                                'insert into tb_county(countyid,countyname,cityid,cityname,state) values(%s,%s,%s,%s,\'1\')',
                                [
                                    country["code"], country["name"],
                                    city["code"], city["name"]
                                ])
        conn.commit()
        cursor.close()
    return 'success'
Ejemplo n.º 3
0
def test():
    cursor = conn.cursor()
    cursor.execute('insert into test(name) values(%s)', ['niu'])
    conn.commit()
    print(cursor.rowcount)
    cursor.close()
    return 'success'
Ejemplo n.º 4
0
def petition():
    cur = conn.cursor()

    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        email = request.form['email']
        story = request.form.get('story')

        mp.people_set(email, {
            '$first_name'    : first_name,
            '$last_name'     : last_name,
            '$email'         : email,
            'story'          : story
        })

        mp.track(email, "Signed Petition");

        cur.execute("INSERT INTO signature (first_name, last_name, email, story) VALUES (%s, %s, %s, %s);", (first_name, last_name, email, story))


    cur.execute("SELECT first_name, last_name FROM signature;")
    results = cur.fetchall()

    signatures = []
    for signature in results:
        signatures.append(signature[0] + ' ' + signature[1])

    cur.close()
    conn.commit()
    return jsonify({"results": signatures})
Ejemplo n.º 5
0
def delete():
    id = request.args.get('id')
    print('................')
    print(id)
    cursor = conn.cursor()
    cursor.execute("delete from tb_table where id=%s", [id])
    row = cursor.rowcount
    conn.commit()
    cursor.close()
    return str(row)
Ejemplo n.º 6
0
    def update_table(tablename, pkcolumn, pk, columnName, newValue):
        try:
            # Formating the string values for raw psycopg2
            if columnName == "name" or columnName == "description" or columnName == "firstname" or columnName == "lastname":
                newValue = Database.format_entry(newValue)

            # Developing the query
            query = "UPDATE %s SET %s = '%s' WHERE %s = %d" % (
                tablename, columnName, newValue, pkcolumn, pk)

            # Executing the query
            cursor.execute(query)

            # Commiting the change
            conn.commit()
        except Exception as error:
            print("Error! %s" % error)
def fetch_to_update():
    if session.get('username'):
        if session.get('usertype') == "rde":
            patientData = {}
            patientid = request.args.get("patientid")
            if patientid:
                cursor.execute(
                    """SELECT (`*`) FROM `patient` WHERE `ws_ssn` LIKE '{}' """
                    .format(patientid))
                patientData = cursor.fetchone()
                #Splitting the address in to Street State and City
                getCompleteAddress = patientData[4].__str__()
                splittedAddress = getCompleteAddress.split(" , ", 2)
                street = splittedAddress[0]
                State = splittedAddress[1]
                city = splittedAddress[2]
                #completeAddress = street +" , "+State+" , "+city
                patient = Patient(patientData[0], patientData[2],
                                  patientData[3], patientData[6], street,
                                  State, city)
            else:
                flash("No patient found")
                return redirect("/update_patient")
            form = UpdatePatient(obj=patient)
            form.populate_obj(patient)
            if form.validate_on_submit():
                ssn = form.patientid.data
                name = form.patient_name.data
                age = form.patient_age.data
                bed = form.bed_type.data
                addrs = form.address.data
                state = form.state.data
                city = form.city.data
                adrs = addrs + " , " + city + " , " + state
                cursor.execute(
                    "UPDATE patient SET ws_pat_name = %s, ws_adrs = %s, ws_age = %s, ws_rtype = %s where ws_ssn = %s",
                    (name, adrs, age, bed, ssn))
                conn.commit()
                flash("Patient Detail Updated")
                return redirect("/create_patient")
            return render_template("update_patient.html", form=form)
    return redirect("/login")
def register():
    registerForm = RegisterForm()
    title = "Register Here"
    if registerForm.validate_on_submit():
        department = registerForm.department.data
        username = registerForm.username.data
        password = registerForm.password.data
        cursor.execute(
            """SELECT (`type`) FROM `user_login` WHERE `username` LIKE '{}' """
            .format(username))
        data = cursor.fetchall()
        if cursor.rowcount > 0:
            flash(f"{username} already exist")
            return redirect(url_for('register'))
        else:
            cursor.execute(
                """INSERT INTO `user_login` (`username`,`password`,`type`) VALUES ('{}','{}','{}')"""
                .format(username, password, department))
            conn.commit()
            return redirect("/login")

    return render_template("register.html", title=title, form=registerForm)
def add_diagnostics():
    if session.get('username'):
        if session.get('usertype') == "dse":
            p_id = request.form.get("ID")
            test_name = request.form.get("name")

            cursor.execute(
                """SELECT * FROM `patient` WHERE `ws_pat_id` LIKE '{}'""".
                format(p_id))
            detail = cursor.fetchall()
            cursor.execute(
                "SELECT * FROM `diag_master_file` WHERE `ws_test_name` LIKE '{}'"
                .format(test_name))
            add = cursor.fetchall()
            print(add)

            cursor.execute(
                "INSERT INTO `track_diag` VALUES ('{}','{}')".format(
                    p_id, add[0][0]))
            conn.commit()
            cursor.execute(
                "SELECT `ws_test_id` FROM `track_diag` WHERE `ws_pat_id` LIKE '{}'"
                .format(p_id))
            all_diag = cursor.fetchall()

            info = list()
            print(all_diag)
            for i in all_diag:
                cursor.execute(
                    "SELECT * FROM `diag_master_file` WHERE `ws_test_id` LIKE '{}'"
                    .format(i[0]))
                some = cursor.fetchall()
                info.append(some[0])

            return render_template("diagnose1.html",
                                   detail=detail,
                                   info=info,
                                   add=add)
    return redirect("/login")
def create_patient():
    if session.get('username'):
        if session.get('usertype') == "rde":
            form = CreatePatientForm()
            if form.validate_on_submit():
                ssn = form.patientid.data
                name = form.patient_name.data
                age = form.patient_age.data
                doj = request.form.get("date")
                bed = form.bed_type.data
                addrs = form.address.data
                state = form.state.data
                city = form.city.data
                adrs = addrs + " , " + city + " , " + state
                cursor.execute(
                    """INSERT INTO `patient` (`ws_ssn`,`ws_pat_name`,`ws_age`,`ws_adrs`,`ws_doj`,`ws_rtype`) VALUES ('{}','{}','{}','{}','{}','{}')"""
                    .format(ssn, name, age, adrs, doj, bed))
                conn.commit()
                flash("Patient Detail Saved")
                return redirect("/create_patient")
            return render_template("CreatePatient.html", form=form)

    return redirect("/login")
def generate_bille():
    if session.get('username'):
        if session.get('usertype') == "rde":
            patientData = {}
            med_detail = {}
            diag_detail = {}
            todaysDate = datetime.now().strftime("%m/%d/%Y")
            totalRoomCost = 0
            doj = 0
            patientid = request.args.get("patientid")
            if patientid:
                cursor.execute(
                    """SELECT (`*`) FROM `patient` WHERE `ws_pat_id` LIKE '{}' """
                    .format(patientid))
                patientData = cursor.fetchone()
                cursor.execute(
                    """SELECT track_medicine.ws_qty, master_med_file.ws_med_name,master_med_file.ws_rate FROM `master_med_file` INNER JOIN `track_medicine` ON master_med_file.ws_med_id=track_medicine.ws_med_id WHERE track_medicine.ws_pat_id LIKE '{}'"""
                    .format(patientid))
                med_detail = cursor.fetchall()

                cursor.execute(
                    """SELECT diag_master_file.ws_test_rate,diag_master_file.ws_test_name FROM `diag_master_file` INNER JOIN `track_diag` ON diag_master_file.ws_test_id=track_diag.ws_test_id WHERE track_diag.ws_pat_id LIKE '{}'"""
                    .format(patientid))

                diag_detail = cursor.fetchall()

                totalMed = 0
                totalDiag = 0

                for med in med_detail:
                    totalMed += (int(med[2]) * int(med[0]))

                for diag in diag_detail:
                    totalDiag += (int(diag[0]))

                #Splitting the address in to Street State and City
                getCompleteAddress = patientData[4].__str__()
                splittedAddress = getCompleteAddress.split(" , ", 2)
                street = splittedAddress[0]
                State = splittedAddress[1]
                city = splittedAddress[2]
                patient = Patient(patientData[0], patientData[2],
                                  patientData[3], patientData[6], street,
                                  State, city)
            else:
                flash("No patient found")
                return redirect("/generate_bill")
            form = ConfirmBill()
            if form.validate_on_submit():
                cursor.execute(
                    "UPDATE `patient` SET `ws_status`='{}' WHERE `ws_pat_id` LIKE '{}'"
                    "".format("Discharged", patientid))
                conn.commit()
                flash("Patient Discharged")
                return redirect("/view_patient")
        #calculate how many days patient stayed
            doj = patientData[5].__str__()
            doj = doj[0:10]
            doj = doj.split("-", 2)
            dojy = int(doj[0])
            dojm = int(doj[1])
            dojd = int(doj[2])
            totalDays = datetime.today() - datetime(dojy, dojm, dojd)
            totalDays = totalDays.__str__()
            totalDays = totalDays[:2]
            totalDays = int(totalDays)

            totalRoomCost = getRoomPrice(patientData[6]) * int(totalDays)

            grandTotal = totalMed + totalDiag + totalRoomCost
            return render_template("patient_bill.html",
                                   patientData=patientData,
                                   totalDays=totalDays,
                                   todaysDate=todaysDate,
                                   totalRoomCost=totalRoomCost,
                                   roomPrice=getRoomPrice(patientData[6]),
                                   med_detail=med_detail,
                                   diag_detail=diag_detail,
                                   totalMed=totalMed,
                                   totalDiag=totalDiag,
                                   grandTotal=grandTotal,
                                   form=form)
    return redirect("/login")
def master_medicine():
    cursor.execute("TRUNCATE TABLE master_med_file")
    conn.commit()
    cursor.execute(
        """INSERT INTO `master_med_file` (`ws_med_id`,`ws_med_name`,`ws_qty_av`,`ws_rate`) VALUES ('01','acetaminophen','400','20')"""
    )
    conn.commit()
    cursor.execute(
        """INSERT INTO `master_med_file` (`ws_med_id`,`ws_med_name`,`ws_qty_av`,`ws_rate`) VALUES ('02','aspirin','500','15')"""
    )
    conn.commit()
    cursor.execute(
        """INSERT INTO `master_med_file` (`ws_med_id`,`ws_med_name`,`ws_qty_av`,`ws_rate`) VALUES ('03','decongestant','350','30')"""
    )
    conn.commit()
    cursor.execute(
        """INSERT INTO `master_med_file` (`ws_med_id`,`ws_med_name`,`ws_qty_av`,`ws_rate`) VALUES ('04','insofurane','400','40')"""
    )
    conn.commit()
    cursor.execute(
        """INSERT INTO `master_med_file` (`ws_med_id`,`ws_med_name`,`ws_qty_av`,`ws_rate`) VALUES ('05','paracetamol','600','10')"""
    )
    conn.commit()
    return "success"
def issue():
    P_id = request.form.get('pt_id')

    cursor.execute(
        """SELECT * FROM `patient` WHERE `ws_pat_id` LIKE '{}'""".format(P_id))
    detail = cursor.fetchall()
    med_name = request.form.get('name')
    med_qty = int(request.form.get('quantity'))
    cursor.execute(
        """SELECT `ws_rate`  FROM `master_med_file` WHERE `ws_med_name` LIKE '{}'"""
        .format(med_name))
    rate = cursor.fetchall()
    amt = med_qty * rate[0][0]
    cursor.execute(
        """SELECT `ws_med_id`  FROM `master_med_file` WHERE `ws_med_name` LIKE '{}'"""
        .format(med_name))
    mid = cursor.fetchall()
    med_id = mid[0][0]
    print(med_id)

    ####### reduce quantity from master_med_file #####
    cursor.execute(
        """SELECT `ws_qty_av`  FROM `master_med_file` WHERE `ws_med_name` LIKE '{}'"""
        .format(med_name))
    quant_to_update = cursor.fetchall()
    new_quant = quant_to_update[0][0] - med_qty
    if new_quant < 0:
        msg = " medicine is not available"
    else:
        cursor.execute(
            """INSERT INTO `track_medicine` (`ws_pat_id`,`ws_med_id`,`ws_qty`) VALUES ('{}','{}','{}')"""
            .format(P_id, med_id, med_qty))
        conn.commit()
        cursor.execute(
            """UPDATE `master_med_file` SET `ws_qty_av`='{}' WHERE `ws_med_name` LIKE '{}'"""
            .format(new_quant, med_name))
        conn.commit()
        msg = None
    print(new_quant)

    ####### patient medicines issued #######
    cursor.execute(
        """SELECT `ws_med_id` FROM `track_medicine` WHERE `ws_pat_id` LIKE '{}'"""
        .format(P_id))
    all_med = cursor.fetchall()

    cursor.execute(
        """SELECT `ws_qty` FROM `track_medicine` WHERE `ws_pat_id` LIKE '{}'"""
        .format(P_id))
    all_qty = cursor.fetchall()
    medicine_name = []
    medicine_rate = []
    medicine_amount = []
    store = []
    for i in all_med:

        cursor.execute(
            """SELECT `ws_med_name` FROM `master_med_file` WHERE `ws_med_id` LIKE '{}'"""
            .format(i[0]))
        nam = cursor.fetchall()
        medicine_name.append(nam)
        cursor.execute(
            """SELECT `ws_rate` FROM `master_med_file` WHERE `ws_med_id` LIKE '{}'"""
            .format(i[0]))
        medrate = cursor.fetchall()
        medicine_rate.append(medrate)
    for j in range(len(all_qty)):
        quant = all_qty[j][0]
        perrate = medicine_rate[j][0][0]
        peramount = quant * perrate
        store.append(int(j))

        medicine_amount.append(peramount)

    return render_template("issue_medicine.html",
                           details=detail,
                           name=med_name,
                           qty=med_qty,
                           rate=rate[0][0],
                           amt=amt,
                           pid=P_id,
                           ALLNAME=medicine_name,
                           ALLQTY=all_qty,
                           ALLRATE=medicine_rate,
                           ALLAMOUNT=medicine_amount,
                           LENGTH=store,
                           message=msg)