Example #1
0
def addDistrict(dist_id, dist_name='districtName', isTracked=False):
    print('*' * 80)
    print('Adding District {} with  id {} '.format(dist_name, dist_id))
    print('*' * 80)
    lastUpdated = common_util.getUtcTimeStamp()
    try:
        session = Session()
        res, isexist = isDistExist(dist_id)
        if isexist == False:
            print('-' * 80)
            print("District ", dist_id, "NOT EXIST IN DB ")
            temp_p = District()
            temp_p.district_name = dist_name
            temp_p.district_id = int(dist_id)
            temp_p.isTrackedAllPin = isTracked
            temp_p.lastUpdated = lastUpdated
            print(temp_p)
            session.add(temp_p)
            session.commit()
            session.close()
            print('-' * 80)

            return 'District added SuccessFully', True
        else:
            print("District  ", dist_id, "EXIST IN DB")

            return 'District Exist in DB ', False

    except Exception as e:

        return 'Exception -->{} '.format(e), False

    finally:
        session.close()
def addCenter(cid, cname, caddr, cpin, fee, block_name):
    try:
        session = Session()

        temp = None
        centerobj = session.query(Center).filter(
            Center.center_id == cid).first()

        if centerobj != None:
            temp = centerobj
        else:
            temp = Center()
        temp.center_name = cname
        temp.center_id = cid
        temp.address = caddr
        temp.pincode = cpin
        temp.fee = fee
        temp.block_name = block_name
        temp.lastUpdated = common_util.getUtcTimeStamp()
        session.add(temp)
        res = session.commit()

        return "Added Center->[{}]".format(res), True

    except Exception as e:
        return "error {} occured while Adding Center {}  for {}".format(
            e, cid, cpin), False

    finally:
        session.close()
def addSessions(sid, cid, min_age, available, avail_dose_1, avail_dose_2,
                slots, date, vaccine_name):
    try:
        session = Session()
        slots = ",".join(slots)
        sid = str(sid)
        cid = int(cid)
        available = int(available)
        date = str(date)
        vaccine_name = str(vaccine_name)
        print("$" * 80)
        # whether Session Exist.
        temp = None
        oldRecord = session.query(VaccineSession).filter(
            VaccineSession.session_id == sid).first()

        print("OLD RECORD-->", oldRecord)

        if oldRecord != None:
            temp = oldRecord
            print("{} {} already Exist hence Updating...".format(
                sid, vaccine_name))
            temp.last_avail_cnt = oldRecord.available
            temp.last_avail_dose_1 = oldRecord.avail_dose_1
            temp.last_avail_dose_2 = oldRecord.avail_dose_2

        else:
            temp = VaccineSession()
            print("{} {} is New Record".format(sid, vaccine_name))
            temp.last_avail_cnt = available
            temp.last_avail_dose_1 = avail_dose_1
            temp.last_avail_dose_2 = avail_dose_2

        temp.session_id = sid
        temp.center_id = cid
        temp.min_age = min_age
        temp.available = available
        temp.avail_dose_1 = avail_dose_1
        temp.avail_dose_2 = avail_dose_2
        temp.slots = slots
        temp.date = date
        temp.vaccine_name = vaccine_name
        temp.lastUpdated = common_util.getUtcTimeStamp()

        # for the first Time Last available is same as avail.
        session.add(temp)
        res = session.commit()

        return "Added Seesion->[{}]".format(res), True

    except Exception as e:
        print("A fatal Exception " + str(e))
        return "error [{}] occured while Adding Sessions of Vaccine for Center[{}]".format(
            e, cid), False

    finally:
        session.close()
Example #4
0
def addPincode(pincode, district_id=-1):
    print('*' * 80)
    print('Adding Pincode {} with dist id {} '.format(pincode, district_id))
    print('*' * 80)
    lastUpdated = common_util.getUtcTimeStamp()
    try:
        session = Session()
        res, isexist = isPincodeExist(pincode)
        if isexist == False:
            print('-' * 80)
            print("PINCODE ", pincode, "NOT EXIST IN DB ")
            temp_p = Pincode()
            temp_p.pincode = int(pincode)
            temp_p.district_id = int(district_id)
            temp_p.lastUpdated = lastUpdated
            print(temp_p)
            session.add(temp_p)
            session.commit()
            session.close()
            print('-' * 80)

            return 'pincode added SuccessFully', True
        else:
            print("PINCODE ", pincode, "EXIST IN DB")

            # pincode exist..
            # now check whether it has District ID or not

            if district_id != -1 and res.district_id == -1:
                print('-+' * 40)
                print(
                    "Updating Pincode {} District id with {} where old dist id was {}"
                    .format(pincode, district_id, res.district_id))

                # queried district id is not provided i.e it is -1
                res.district_id = int(district_id)
                res.lastUpdated = lastUpdated
                session.add(res)
                session.commit()
                print('-+' * 40)

                # updated Pincode with District Id

            # else pincode already exist and no modification is going to be done .

            return 'Pincode Exists[no modification done]', False

    except Exception as e:

        return 'Exception -->{} '.format(e), False

    finally:
        session.close()
Example #5
0
def updateLastUpdated(pincode):
    try:
        session = Session()
        pinObj = session.query(Pincode).filter(
            Pincode.pincode == pincode).first()
        if pinObj == None:
            raise Exception
        pinObj.lastUpdated = common_util.getUtcTimeStamp()
        session.add(pinObj)
        session.commit()

        return "Updated LastUpdated Successfully", True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
Example #6
0
def updateLastUpdated(dist_id):
    try:
        session = Session()
        Obj = session.query(District).filter(
            District.district_id == dist_id).first()
        if Obj == None:
            raise Exception
        Obj.lastUpdated = common_util.getUtcTimeStamp()
        session.add(Obj)
        session.commit()

        return "Updated LastUpdated Successfully", True
    except Exception as e:
        return 'Not Found e->{}'.format(e), False
    finally:
        session.close()
Example #7
0
def trackComplete(dist_id):
    try:

        session = Session()
        district = session.query(District).filter(
            District.district_id == dist_id).first()
        district.lastUpdated = common_util.getUtcTimeStamp()
        district.isTrackedAllPin = True

        session.add(district)
        session.commit()

        return 'Districts All pin tracked successfully', True

    except Exception as e:
        return "Exception occurred {}".format(e), False

    finally:
        session.close()