Exemplo n.º 1
0
def set_visit(request):
    relevant_data = json.loads(request.body)
    patient_id = relevant_data['patient_id']
    s_date = relevant_data['date']
    array_date = []
    array_date.append(s_date)
    print(array_date)
    #s_time = relevant_data['time']

    cur.execute(
        "UPDATE smo_anc  SET doctor_schedule_date = doctor_schedule_date || %s::DATE[] , schedule_status = True WHERE patient_id = %s ",
        (
            array_date,
            patient_id,
        ))
    #cur.execute("UPDATE patient_level SET schedule_status=True WHERE patient_id=%s", (patient_id,))
    conn.commit()
    cur.execute(
        " SELECT doctor_schedule_date FROM smo_anc WHERE patient_id = %s",
        (patient_id, ))
    records = cur.fetchall()
    print("dates array length : ", len(records[0][0]))
    l = len(records[0][0])

    resp = str(l) + " visit scheduled"
    return Response(resp)
Exemplo n.º 2
0
def pnc_visit(request):
    id = request.user.id
    smo_id = find_smo_id(request.user)
    relevant_data = json.loads(request.body)
    p_id = relevant_data['patient_id']

    visit_date = relevant_data["v_date"]
    mother_status = relevant_data["m_status"]
    stutch = (relevant_data["stutch"], None)
    color_lochia = relevant_data["color_lochia"]
    oedema = relevant_data["oedema"]
    breast_feeding = relevant_data["breast_feed"]
    breast_infection = relevant_data["breast_infec"]
    infant_danger = relevant_data["danger"]

    cur.execute(
        """INSERT INTO smo_pnc (patient_id, v_date, mother_status, stutch, color_lochia, oedema,
    breast_feed, breast_infec, infant_danger,pnc_check) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,True)""",
        (p_id, visit_date, mother_status, stutch, color_lochia, oedema,
         breast_feeding, breast_infection, infant_danger))

    cur.execute("UPDATE patient_level SET pnc_check=True WHERE patient_id=%s",
                (p_id, ))

    conn.commit()

    return Response("PNC Details Saved")
Exemplo n.º 3
0
def delivery_details(request):
    id = request.user.id
    smo_id = find_smo_id(request.user)
    relevant_data = json.loads(request.body)
    p_id = relevant_data['patient_id']
    delivery_status = True
    date_of_del = relevant_data["dod"]
    time_of_del = relevant_data["tod"]
    place_of_del = relevant_data["place"]
    conducted_by = relevant_data["conducted_by"]
    delivery_type = relevant_data["del_type"]
    complications = relevant_data["complications"]
    discharge_date = relevant_data["disch_date"]
    delivery_outcome = relevant_data["d_outcome"]
    live_count = relevant_data["live"]
    still_count = relevant_data["still"]
    baby_weight = relevant_data["b_weight"]
    infant_danger = relevant_data["infant_danger"]

    cur.execute(
        """INSERT INTO delivery_details (patient_id,dod,tod,place,conducted_by,delivery_type,
    complications, discharge_date, d_outcome, live,still, b_weight, infant_danger) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
        (p_id, date_of_del, time_of_del, place_of_del, conducted_by,
         delivery_type, complications, discharge_date, delivery_outcome,
         live_count, still_count, baby_weight, infant_danger))

    cur.execute(
        "UPDATE patient_level SET delivery_status = TRUE WHERE patient_id = %s",
        (p_id, ))

    conn.commit()

    return Response("Delivery Details Saved")
Exemplo n.º 4
0
def device_registeration(request):
    relevant_data = json.loads(request.body)
    device_id = relevant_data["reg_token"]
    cur.execute("UPDATE auth_user SET device_id = %s WHERE username = %s", (
        device_id,
        str(request.user),
    ))
    conn.commit()
    return Response("Registeration Token Saved")
Exemplo n.º 5
0
def check_update(request):
    cur.execute(
        "SELECT * FROM patient_level WHERE high_risk_check = 'true' and notified = False"
    )
    records = cur.fetchall()
    if len(records) > 0:
        print(records[0][0])
        cur.execute(
            "UPDATE patient_level SET notified = %s WHERE patient_id = %s", (
                True,
                records[0][0],
            ))
        #conn.commit()
        return Response({'patient_details': records[0]})
    conn.commit()
    return Response("No Update")
Exemplo n.º 6
0
def final_visit(request):
    id = request.user.id
    smo_id = find_smo_id(request.user)
    relevant_data = json.loads(request.body)
    p_id = relevant_data['patient_id']

    maternal_status = relevant_data["m_status"]

    cur.execute(
        "UPDATE smo_pnc SET maternal_status = %s WHERE patient_id = %s",
        (maternal_status, p_id))
    cur.execute(
        "UPDATE patient_level SET pnc_42_check=True WHERE patient_id=%s",
        (p_id, ))
    conn.commit()

    return Response("Maternal Status Saved")
Exemplo n.º 7
0
def patient_registry(request):
    anm_id = get_anm_id(request.user)
    id = request.user.id
    relevant_data = json.loads(request.body)
    location = address_mapping(id)
    state = location['state']  #14
    block = location['block']  #15
    division = location['division']  #16
    district = location['district']  #17
    aadhar_number = relevant_data['aadhar_number']  #1
    patient_name = relevant_data['patient_name']  # 2
    husband_name = relevant_data['husband_name']  # 3
    #husband_age = relevant_data["husband_age"] #4
    mobile_number = relevant_data['mobile_number']  # 5
    date_of_birth = relevant_data['date_of_birth']  # 6
    age = relevant_data['age']
    economic_status = relevant_data['economic_status']  # 7
    cast = relevant_data['cast']  # 8
    relegion = relevant_data['relegion']  # 9
    lmp_date = relevant_data['lmp_date']  # 10
    edd_date = relevant_data['edd_date']  # 11
    #officer = relevant_data['officer']  # 12
    smo_id = get_smo_id(request.user)
    address = relevant_data["address"]
    #agbdi = relevant_data["agbdi"]
    #agbdi_name = relevant_data['agbdi_name'] #13

    cur.execute(
        """INSERT INTO patient_level (state,block,division,district,aadhar_number,patient_name,husband_name,mobile_number,
                   date_of_birth,age,economic_status,cast_type,relegion,lmp_date,edd_date,address,smo_id,anm_id) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s ) 
                   RETURNING patient_id """,
        (state, block, division, district, aadhar_number, patient_name,
         husband_name, mobile_number, date_of_birth, age, economic_status,
         cast, relegion, lmp_date, edd_date, address, smo_id, anm_id))
    conn.commit()
    res = cur.fetchall()
    print(res)
    patient_id = res[0][0]

    return Response({'patient_id': patient_id})
Exemplo n.º 8
0
def smo_anc_visit(request):
    id = request.user.id
    #anm_id = get_anm_id(request.user)
    smo_id = find_smo_id(request.user)
    relevant_data = json.loads(request.body)
    p_id = relevant_data['patient_id']
    c_ctr = 0
    v_ctr = 0
    hrisk_check = False
    hrisk_factors = ""
    const_factors = ""
    variable_factors = ""
    h_f = []
    c_f = []
    v_f = []

    visit_number = get_visit_number(p_id)

    # variable high risk factors check
    # weight = []

    weight = (relevant_data['weight'])  # 13
    if (weight < 40 or weight > 90):
        v_ctr += 1
        variable_factors += ('weight ')
    # bp1 = []
    # bp2 = []
    bp1 = (relevant_data['bp1'])  # 14
    bp2 = (relevant_data['bp2'])  # 15
    if (bp1 > 140 or bp2 > 90):
        v_ctr += 1
        variable_factors += ('bp ')

    # malrep = []
    malrep = (relevant_data["malrep"])
    if (not (malrep == 'Normal')):
        v_ctr += 1
        variable_factors += ('malrepresentation ')

    # gdm = []
    gdm = (relevant_data["gdm"])
    if (gdm > 139):
        v_ctr += 1
        variable_factors += ("gdm ")

    # anemia = []
    anemia = (relevant_data['anemia'])  # 18
    if (not (anemia == 'None')):
        v_ctr += 1
        variable_factors += ('anemia ')

    # hb = []
    hb = (relevant_data['hb'])  # 19
    if (hb < 8):
        v_ctr += 1
        variable_factors += ('haemoglobin ')

    # thyroid = []
    thyroid = (relevant_data['thyroid'])  # 20
    if (not (thyroid == 'Normal')):
        v_ctr += 1
        variable_factors += ('thyroid ')

    tobacohol = []
    tobacohol = (relevant_data['alcohol_tobacco'])  # 21
    if (tobacohol == True):
        v_ctr += 1
        variable_factors += ('alcohol_tobacco ')

    # vdrl = []
    vdrl = (relevant_data['vdrl'])  # 22
    if (vdrl == True):
        v_ctr += 1
        variable_factors += ('vdrl ')

    # preg_disease = []
    preg_disease = (relevant_data['preg_disease'])  # 23
    if (not (preg_disease == 'Adequate')):
        v_ctr += 1
        variable_factors += ('preg_disease ')

    # bleeding_check = []
    bleeding_check = (relevant_data['bleeding_check'])  # 24
    if (bleeding_check == True):
        variable_factors += ('bleeding ')

    # iugr = []
    iugr = (relevant_data['iugr'])  # 25
    if (iugr == True):
        variable_factors += ('iugr ')

    # alb = []
    alb = (relevant_data['alb'])  # 25
    if (not (alb == "None")):
        variable_factors += ('alb ')

    #dietary_advice = relevant_data["dietary_advice"]

    if (c_ctr > 0 or v_ctr > 0):
        hrisk_check = True
        hrisk_factors += (const_factors)
        hrisk_factors += (variable_factors)

    if (hrisk_check == False):
        hrisk_check = relevant_data['hrisk_check']

    print("high risk value " + str(hrisk_check))
    advice = (relevant_data["d_advice"])
    visit_number += 1

    v_date = (datetime.date.today())

    cur.execute(
        """UPDATE smo_anc SET weight = array_append(weight, %s), bp_1 = array_append(bp_1, %s),bp_2=array_append(bp_2,%s),
    malrepresentation=array_append(malrepresentation,%s),gdm=array_append(gdm,%s),anemia=array_append(anemia,%s),haemoglobin=array_append(haemoglobin,%s),
        thyroid=array_append(thyroid,%s), alcohol_tobacco_check=array_append(alcohol_tobacco_check,%s),preg_related_disease = array_append(preg_related_disease, %s),
        bleeding_check = array_append(bleeding_check, %s), iugr = array_append(iugr, %s),constant_factors = array_append(constant_factors, %s),
        variable_factors = array_append(variable_factors, %s),hrisk_factors = array_append(hrisk_factors, %s),actual_vdate = array_append(actual_vdate, %s),
        visits_done = %s 
        WHERE patient_id=%s""", (
            weight,
            bp1,
            bp2,
            malrep,
            gdm,
            anemia,
            hb,
            thyroid,
            tobacohol,
            preg_disease,
            bleeding_check,
            iugr,
            const_factors,
            variable_factors,
            hrisk_factors,
            v_date,
            visit_number,
            p_id,
        ))

    cur.execute("SELECT edd_date FROM patient_level WHERE patient_id=%s",
                (p_id, ))
    rec_edd = cur.fetchall()
    edd_date = rec_edd[0][0]

    cur.execute("SELECT visit_dates FROM smo_anc WHERE patient_id=%s",
                (p_id, ))
    rec_dates = cur.fetchall()
    dates = rec_dates[0][0]
    length = len(dates)
    last_date = dates[length]

    days_left_ldate = (last_date - v_date).days

    days_left_edd = (edd_date - v_date).days

    if (days_left_edd < 15 or visit_number == 4 or days_left_ldate < 15):
        cur.execute(
            "UPDATE patient_level SET delivery_status=True WHERE patient_id = %s ",
            (p_id, ))
    else:
        cur.execute(
            "UPDATE patient_level SET schedule_status=False WHERE patient_id = %s ",
            (p_id, ))

    conn.commit()
    return Response("Visit " + str(visit_number) + " Data Updated")
Exemplo n.º 9
0
def update_patient_data(request):
    sample = []
    var_sample = []
    relevant_data = json.loads(request.body)
    #visit_number = relevant_data["visit_no"]
    patient_id = relevant_data["patient_id"]
    cur.execute(
        " SELECT doctor_visits FROM patient_level WHERE patient_id = %s",
        (patient_id, ))
    records = cur.fetchall()
    print("visit number ", records[0][0])

    visit_number = int(records[0][0])

    cur.execute("SELECT visit_data FROM patient_level WHERE patient_id = %s",
                (patient_id, ))
    records = cur.fetchall()
    if (records[0][0] == None):
        visit_data = []
    else:
        visit_data = records[0][0]

    cur.execute("SELECT var_reasons FROM patient_level WHERE patient_id = %s",
                (patient_id, ))
    records = cur.fetchall()
    if (records[0][0] == None):
        var_reasons = []
    else:
        var_reasons = records[0][0]
    #var_reasons = []

    sample.append(str(datetime.date.today()))
    new_weight = relevant_data["weight"]
    sample.append(new_weight)

    new_bp1 = int(relevant_data["bp1"])
    sample.append(new_bp1)
    new_bp2 = int(relevant_data["bp2"])
    sample.append(new_bp2)
    if (new_bp1 > 130 or new_bp2 > 90):
        print("bp is the reason")
        var_check = "yes"

        var_sample.append("bp")
    else:
        var_sample.append('')

    new_sugar = int(relevant_data["sugar"])
    sample.append(new_sugar)

    if (new_sugar > 139):
        print("sugar is the reason")
        var_check = "yes"
        var_sample.append("sugar")
    else:
        var_sample.append('')

    new_haemoglobin = int(relevant_data["haemoglobin"])
    sample.append(new_haemoglobin)
    if (new_haemoglobin < 10):
        print("haemoglobin is the reason")
        var_check = "yes"
        #high_risk_check = True
        var_sample.append("haemoglobin")
    else:
        var_sample.append('')

    new_dietary_advice = relevant_data["dietary_advice"]
    sample.append(new_dietary_advice)

    new_image_link = relevant_data["image_url"]
    sample.append(new_image_link)

    visit_number += 1
    visit_data.append(sample)

    #var_sample.append('')
    var_reasons.append(var_sample)
    print("var reasons is ", var_reasons)
    improv2 = []
    if (visit_number == 2):
        print("visit 2 improvement being checked")
        for v in var_reasons[1]:
            print(v)
            if (not v in var_sample):
                improv2.append(v)

        cur.execute(
            "UPDATE patient_level SET visit_data = %s::TEXT[][], var_reasons = %s::TEXT[][],doctor_visits=%s,improv2=%s::TEXT[] WHERE patient_id = %s",
            (
                visit_data,
                var_reasons,
                visit_number,
                improv2,
                patient_id,
            ))

    if (visit_number == 3):
        improv3 = []
        for v in var_reasons[2]:
            if (not v in var_sample):
                improv3.append(v)

        cur.execute(
            "UPDATE patient_level SET visit_data = %s::TEXT[][], var_reasons = %s::TEXT[][],doctor_visits=%s,improv3=%s::TEXT[] WHERE patient_id = %s",
            (
                visit_data,
                var_reasons,
                visit_number,
                improv3,
                patient_id,
            ))

    if (visit_number == 4):
        improv4 = []
        for v in var_reasons[3]:
            if (not v in var_sample):
                improv4.append(v)

        cur.execute(
            "UPDATE patient_level SET visit_data = %s::TEXT[][], var_reasons = %s::TEXT[][],doctor_visits=%s,improv4=%s::TEXT[] WHERE patient_id = %s",
            (
                visit_data,
                var_reasons,
                visit_number,
                improv4,
                patient_id,
            ))

    print("visit data is ", visit_data)
    cur.execute(
        "UPDATE patient_level SET visit_data = %s::TEXT[][], var_reasons = %s::TEXT[][],doctor_visits=%s WHERE patient_id = %s",
        (
            visit_data,
            var_reasons,
            visit_number,
            patient_id,
        ))

    conn.commit()
    #testing output
    cur.execute("SELECT visit_data FROM patient_level WHERE patient_id = %s",
                (patient_id, ))
    records = cur.fetchall()
    print("visit data length: ", len(records))
    print("visit_data[0] length ", len(records[0]))
    print("visit data[0][0] length ", len(records[0][0]))
    print("visit data is ", records[0][0])
    ##

    cur.execute("SELECT var_reasons FROM patient_level WHERE patient_id = %s",
                (patient_id, ))
    records = cur.fetchall()
    print("var_reasons length: ", len(records))
    print("var_reasons[0] length ", len(records[0]))
    print("var_reasons[0][0] length ", len(records[0][0]))
    print(records[0][0])
    conn.commit()
    return Response("Data already saved for 3 visits!!")
Exemplo n.º 10
0
def anc_visit(request):
    id = request.user.id
    anm_id = get_anm_id(request.user)
    smo_id = get_smo_id(request.user)
    relevant_data = json.loads(request.body)
    print((relevant_data))
    p_id = relevant_data['patient_id']
    c_ctr = 0
    v_ctr = 0
    hrisk_check = False
    hrisk_factors = ""
    const_factors = ""
    variable_factors = ""
    h_f = []
    c_f = []
    v_f = []

    visit_number = get_visit_number_anm(p_id)

    #constant high risk factors check
    cur.execute(
        "SELECT age,lmp_date,edd_date,created_at::DATE,patient_name FROM patient_level WHERE patient_id = %s",
        (p_id, ))
    print(p_id)
    age_rec = cur.fetchall()
    print(len(age_rec))
    print(age_rec)
    age = age_rec[0][0]  #1
    lmp = age_rec[0][1]
    edd = age_rec[0][2]
    reg_date = age_rec[0][3]
    patient_name = age_rec[0][4]
    cur.execute("SELECT height FROM anm_anc WHERE patient_id = %s", (p_id, ))
    rec_height = cur.fetchall()

    if (len(rec_height) == 0):
        anm_anc_date = []
        anm_anc_date.append(relevant_data["anm_anc_date"])

        if (age < 18 or age > 35):
            c_ctr += 1
            const_factors += ('age ')
            print("age is reason")

        height = relevant_data['height']  #2
        if (height < 145):
            c_ctr += 1
            const_factors += ('height ')
            print("height is reason")

        previous_lscs = relevant_data['previous_lscs']  #3
        if (previous_lscs == True):
            c_ctr += 1
            const_factors += ('previous_lscs ')
            print("p_lscs is reason")

        bgroup = relevant_data['bgroup']  #4
        if (bgroup in hrisk_bgroups):
            c_ctr += 1
            const_factors += ('blood group ')
            print("blood group is reason")

        disability = relevant_data['disability']  #5
        if (not (disability == 'None')):
            c_ctr += 1
            const_factors += ('disability ')
            print("disablity is reason")

        blood_disease = relevant_data['blood_disease']  #6
        if (not (blood_disease == 'Normal')):
            c_ctr += 1
            const_factors += ('blood disease ')
            print("blood disease is reason")

        hiv = relevant_data['hiv']  #7
        if (hiv == True):
            c_ctr += 1
            const_factors += ('hiv ')
            print("HIV is reason")

        hbsag = relevant_data['hbsag']  #8
        if (hbsag == True):
            c_ctr += 1
            const_factors += ('HbsAg ')
            print("Hbsag is reason")

        cardiac = relevant_data['cardiac']  #9
        if (cardiac == True):
            c_ctr += 1
            const_factors += ('cardiac_disease ')
            print("cardiac is reason")

        p_uterus = relevant_data['p_uterus']  #10
        if (p_uterus == True):
            c_ctr += 1
            const_factors += ('prolapse_uterus ')
            print("prolapse uterus is reason")

        asthama = relevant_data['asthama']  #11
        if (asthama == True):
            c_ctr += 1
            const_factors += ('asthama ')
            print("asthama is reason")

        twin_delivery = relevant_data['twin_delivery']  #12
        if (twin_delivery == True):
            c_ctr += 1
            const_factors += ('twin_delivery ')
            print("twin delivery is reason")

        gravita = relevant_data['gravita']
        para = relevant_data['para']
        live = relevant_data['live']
        abortion = relevant_data['abortion']

        if (abortion > 0):
            c_ctr += 1
            const_factors += ('abortion ')
            print("abortion is reason")

    ########################################################

    #variable high risk factors check
        weight = []
        weight.append(relevant_data['weight'])  #13
        if (weight[0] < 40 or weight[0] > 90):
            v_ctr += 1
            variable_factors += ('weight ')
            print("weight is reason")

        bp1 = []
        bp2 = []
        bp1.append(relevant_data['bp1'])  #14
        bp2.append(relevant_data['bp2'])  #15
        if (bp1[0] > 140 or bp2[0] > 90):
            v_ctr += 1
            variable_factors += ('bp ')
            print("BP is reason")

        malrep = []
        malrep.append(relevant_data["malrep"])
        if (not (malrep[0] == "Normal")):
            v_ctr += 1
            variable_factors += ('malrepresentation ')
            print("malrepresentation is reason")

        gdm = []
        gdm.append(relevant_data["gdm"])
        if (gdm[0] > 139):
            v_ctr += 1
            variable_factors += ("gdm ")
            print("gdm is reason")

        anemia = []
        anemia.append(relevant_data['anemia'])  #18
        if (not (anemia[0] == 'None')):
            v_ctr += 1
            variable_factors += ('anemia ')
            print("anemia is reason")

        hb = []
        hb.append(relevant_data['hb'])  #19
        if (hb[0] < 8):
            v_ctr += 1
            variable_factors += ('haemoglobin ')
            print("HB is reason")

        thyroid = []
        thyroid.append(relevant_data['thyroid'])  #20
        if (not (thyroid[0] == 'Normal')):
            v_ctr += 1
            variable_factors += ('thyroid ')
            print("thyroid is reason")

        tobacohol = []
        tobacohol.append(relevant_data['alcohol_tobacco'])  #21
        if (tobacohol[0] == True):
            v_ctr += 1
            variable_factors += ('alcohol_tobacco ')
            print("tobacohol is reason")

        vdrl = []
        vdrl.append(relevant_data['vdrl'])  #22
        if (vdrl[0] == True):
            v_ctr += 1
            variable_factors += ('vdrl ')
            print("vdrl is reason")

        preg_disease = []
        preg_disease.append(relevant_data['preg_disease'])  #23
        if (not (preg_disease[0] == 'Adequate')):
            v_ctr += 1
            variable_factors += ('preg_disease ')
            print("preg related disease is reason")

        bleeding_check = []
        bleeding_check.append(relevant_data['bleeding_check'])  #24
        if (bleeding_check[0] == True):
            variable_factors += ('bleeding ')
            print("bleeding is reason")

        iugr = []
        iugr.append(relevant_data['iugr'])  #25
        if (iugr[0] == True):
            variable_factors += ('iugr ')
            print("iugr is reason")

        alb = []
        alb.append(relevant_data['alb'])  #25
        if (not (alb[0] == "None")):
            variable_factors += ('alb ')
            print("ALB is reason")

        #dietary_advice = []

        if (c_ctr > 0 or v_ctr > 0):
            hrisk_check = True
            hrisk_factors += (const_factors)
            hrisk_factors += (variable_factors)

        if (hrisk_check == False):
            hrisk_check = relevant_data['hrisk_check']

        h_f.append(hrisk_factors)
        c_f.append(const_factors)
        v_f.append(variable_factors)
        visit_number += 1
        print("visit number is  : " + str(visit_number))
        print("high risk value " + str(hrisk_check))
        cur.execute(
            """INSERT INTO anm_anc (patient_id,anm_anc_date,age,height, previous_lscs, blood_group,disability,blood_disease,
        hiv_check,hbsag,cardiac_disease,prolapse_uterus,asthama,twin_delivery,gravita,para,live,abortion,weight,bp_1,bp_2,malrepresentation,gdm,anemia,
        haemoglobin,thyroid, alcohol_tobacco_check,preg_related_disease,bleeding_check,iugr,alb,hrisk_check,
        constant_factors, variable_factors,hrisk_factors,anm_id,visit_no) VALUES (%s,%s::DATE[],%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
            (
                p_id,
                anm_anc_date,
                age,
                height,
                previous_lscs,
                bgroup,
                disability,
                blood_disease,
                hiv,
                hbsag,
                cardiac,
                p_uterus,
                asthama,
                twin_delivery,
                gravita,
                para,
                live,
                abortion,
                weight,
                bp1,
                bp2,
                malrep,
                gdm,
                anemia,
                hb,
                thyroid,
                tobacohol,
                preg_disease,
                bleeding_check,
                iugr,
                alb,
                hrisk_check,
                c_f,
                v_f,
                h_f,
                anm_id,
                visit_number,
            ))

        cur.execute(
            "UPDATE patient_level SET anc_check=true WHERE patient_id=%s",
            (p_id, ))
        conn.commit()
        print(("anc_check set true done"))

        if (hrisk_check == True):
            cur.execute(
                "UPDATE patient_level SET high_risk_check=True WHERE patient_id = %s",
                (p_id, ))

            visit_dates = []
            visit_dates = visit_schedule(lmp, edd, reg_date)
            # add record to smo_anc table as 0th visit data

            cur.execute(
                """INSERT INTO smo_anc (patient_id,weight,bp_1,bp_2,malrepresentation,gdm,anemia,
                    haemoglobin,thyroid, alcohol_tobacco_check,preg_related_disease,bleeding_check,iugr,alb,hrisk_check,
                    constant_factors, variable_factors,hrisk_factors,smo_id,visits_done,visit_dates) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
                (p_id, weight, bp1, bp2, malrep, gdm, anemia, hb, thyroid,
                 tobacohol, preg_disease, bleeding_check, iugr, alb,
                 hrisk_check, c_f, v_f, h_f, smo_id, 0, visit_dates))

            print("smo_id" + str(smo_id))

            officer = get_smo_name(smo_id)
            notify_smo(officer)
            text_to_smo(p_id, officer, patient_name)
            # text_to_supervisor(anm_id,p_id)

            conn.commit()

        return Response({"high_risk": hrisk_check})

    else:
        ########################################################
        print("hrisk value before checks is " + str(hrisk_check))

        # variable high risk factors check
        anm_anc_date = relevant_data["anm_anc_date"]

        #weight = []
        weight = (relevant_data['weight'])  # 13
        if (weight < 40 or weight > 90):
            v_ctr += 1
            variable_factors += ('weight ')
            print("weight is true")
        #bp1 = []
        #bp2 = []
        bp1 = (relevant_data['bp1'])  # 14
        bp2 = (relevant_data['bp2'])  # 15
        if (bp1 > 140 or bp2 > 90):
            v_ctr += 1
            variable_factors += ('bp ')
            print("bp is true")

        #malrep = []
        malrep = (relevant_data["malrep"])
        if (not (malrep == 'Normal')):
            v_ctr += 1
            variable_factors += ('malrepresentation ')
            print("malrep is true")
        #gdm = []
        gdm = (relevant_data["gdm"])
        if (gdm > 139):
            v_ctr += 1
            variable_factors += ("gdm ")
            print("gdm is true")
        #anemia = []
        anemia = (relevant_data['anemia'])  # 18
        if (not (anemia == 'None')):
            v_ctr += 1
            variable_factors += ('anemia ')
            print("anemia is true")

        #hb = []
        hb = (relevant_data['hb'])  # 19
        if (hb < 8):
            v_ctr += 1
            variable_factors += ('haemoglobin ')
            print("HB is true")

        #thyroid = []
        thyroid = (relevant_data['thyroid'])  # 20
        if (not (thyroid == 'Normal')):
            v_ctr += 1
            variable_factors += ('thyroid ')
            print("thyroid is true")
        tobacohol = []
        tobacohol = (relevant_data['alcohol_tobacco'])  # 21
        if (tobacohol == True):
            v_ctr += 1
            variable_factors += ('alcohol_tobacco ')
            print("alcohol is true")
        #vdrl = []
        vdrl = (relevant_data['vdrl'])  # 22
        if (vdrl == True):
            v_ctr += 1
            variable_factors += ('vdrl ')
            print("vdrl is true")
        #preg_disease = []
        preg_disease = (relevant_data['preg_disease'])  # 23
        if (not (preg_disease == 'Adequate')):
            v_ctr += 1
            variable_factors += ('preg_disease ')
            print("preg_disease is true")
        #bleeding_check = []
        bleeding_check = (relevant_data['bleeding_check'])  # 24
        if (bleeding_check == True):
            variable_factors += ('bleeding ')
            print("bleeding is true")
        #iugr = []
        iugr = (relevant_data['iugr'])  # 25
        if (iugr == True):
            variable_factors += ('iugr ')
            print("iugr is true")
        #alb = []
        alb = (relevant_data['alb'])  # 25
        if (not (alb == "None")):
            variable_factors += ('alb ')
            print("alb is true")

        if (c_ctr > 0 or v_ctr > 0):
            hrisk_check = True
            hrisk_factors += (const_factors)
            hrisk_factors += (variable_factors)

        if (hrisk_check == False):
            hrisk_check = relevant_data['hrisk_check']

        visit_number += 1
        print("visit number is now " + str(visit_number))
        print("high risk value " + str(hrisk_check))
        h_f.append(hrisk_factors)
        c_f.append(const_factors)
        v_f.append(variable_factors)

        #cur.execute("""INSERT INTO anm_anc (patient_id,age,height, previous_lscs, blood_group,disability,blood_disease,
        #    hiv_check,hbsag,cardiac_disease,prolapse_uterus,asthama,twin_delivery,gravita,para,live,abortion,weight,bp_1,bp_2,malrepresentation,gdm,anemia,
        #    haemoglobin,thyroid, alcohol_tobacco_check,preg_related_disease,bleeding_check,iugr,alb,hrisk_check,
        #    constant_factors, variable_factors,hrisk_factors,anm_id) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
        #            (p_id, age, height, previous_lscs, bgroup, disability, blood_disease, hiv, hbsag, cardiac, p_uterus,
        #             asthama,
        #             twin_delivery, gravita, para, live, abortion, weight, bp1, bp2, malrep, gdm, anemia, hb, thyroid,
        #             tobacohol, preg_disease, bleeding_check, iugr, alb,
        #             hrisk_check, c_f, v_f, h_f, anm_id))

        # bp_1=%s::INTEGER[] ,bp_2=%s::INTEGER[] ,malrepresentation=%s::TEXT[] ,gdm=%s::INTEGER[] ,anemia=%s::TEXT[] ,
        #        haemoglobin=%s::INTEGER[] ,thyroid=%s::TEXT[] , alcohol_tobacco_check=%s::BOOLEAN[] ,preg_related_disease=%s::BOOLEAN[] ,bleeding_check=%s::BOOLEAN[] ,iugr=%s::BOOLEAN[] ,

        cur.execute(
            """UPDATE anm_anc SET weight=array_append(weight, %s) ,bp_1=array_append(bp_1,%s),bp_2=array_append(bp_2,%s),
        malrepresentation=array_append(malrepresentation,%s),gdm=array_append(gdm,%s),anemia=array_append(anemia,%s),haemoglobin=array_append(haemoglobin,%s),
        thyroid=array_append(thyroid,%s), alcohol_tobacco_check=array_append(alcohol_tobacco_check,%s),preg_related_disease=array_append(preg_related_disease,%s),
        bleeding_check=array_append(bleeding_check,%s),iugr=array_append(iugr,%s),alb=array_append(alb,%s),
                constant_factors=array_append(constant_factors,%s) , variable_factors=array_append(variable_factors,%s) ,
                hrisk_factors=array_append(hrisk_factors,%s),
                visit_no=%s,hrisk_check=%s, anm_anc_date=array_append(anm_anc_date, %s) WHERE patient_id = %s""",
            (
                weight,
                bp1,
                bp2,
                malrep,
                gdm,
                anemia,
                hb,
                thyroid,
                tobacohol,
                preg_disease,
                bleeding_check,
                iugr,
                alb,
                const_factors,
                variable_factors,
                hrisk_factors,
                visit_number,
                hrisk_check,
                anm_anc_date,
                p_id,
            ))
        #cur.execute("UPDATE anm_anc SET weight=array_append(weight, %s) WHERE patient_id=%s",(weight,p_id,))
        conn.commit()

        if (hrisk_check == True):
            cur.execute(
                "UPDATE patient_level SET high_risk_check=True WHERE patient_id = %s",
                (p_id, ))

            visit_dates = []
            visit_dates = visit_schedule(lmp, edd, reg_date)
            #add record to smo_anc table as 0th visit data

            cur.execute(
                """INSERT INTO smo_anc (patient_id,weight,bp_1,bp_2,malrepresentation,gdm,anemia,
                haemoglobin,thyroid, alcohol_tobacco_check,preg_related_disease,bleeding_check,iugr,alb,hrisk_check,
                constant_factors, variable_factors,hrisk_factors,smo_id,visits_done,visit_dates) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
                (p_id, [weight], [bp1], [bp2], [malrep], [gdm], [anemia], [hb],
                 [thyroid], [tobacohol], [preg_disease], [bleeding_check], [
                     iugr
                 ], [alb], hrisk_check, c_f, v_f, h_f, smo_id, 0, visit_dates))

            print("smo_id" + str(smo_id))

            officer = get_smo_name(smo_id)
            notify_smo(officer)
            text_to_smo(p_id, officer, patient_name)
            #text_to_supervisor(anm_id,p_id)

            conn.commit()

        return Response({"high_risk": hrisk_check})