def reschedule_vaccination(dbo, username, vaccinationid, newdays): """ Marks a vaccination completed today (if it's not already completed) and reschedules it for given + newdays onwards. """ av = db.query( dbo, "SELECT * FROM animalvaccination WHERE ID = %d" % int(vaccinationid))[0] given = av["DATEOFVACCINATION"] if given is None: given = now(dbo.timezone) db.execute( dbo, "UPDATE animalvaccination SET DateOfVaccination = %s WHERE ID = %d" % (db.dd(now(dbo.timezone)), int(vaccinationid))) audit.edit(dbo, username, "animalvaccination", str(vaccinationid) + " => given") nvaccid = db.get_id(dbo, "animalvaccination") db.execute( dbo, db.make_insert_user_sql( dbo, "animalvaccination", username, (("ID", db.di(nvaccid)), ("AnimalID", db.di(av["ANIMALID"])), ("VaccinationID", db.di(av["VACCINATIONID"])), ("DateOfVaccination", db.dd(None)), ("DateRequired", db.dd(add_days(given, int(newdays)))), ("Cost", db.di(av["COST"])), ("Comments", db.ds(av["COMMENTS"]))))) audit.create(dbo, username, "animalvaccination", str(nvaccid))
def execute_diary_task(dbo, username, tasktype, taskid, linkid, selecteddate): """ Runs a diary task tasktype: ANIMAL or PERSON taskid: The ID of the diarytaskhead record to run linkid: The ID of the animal or person to run against selecteddate: If the task has any detail records with a pivot of 0, the date to supply (as python date) """ def fix(s): return s.replace("<", "<").replace(">", ">") rollingdate = dbo.today() dtd = dbo.query( "SELECT * FROM diarytaskdetail WHERE DiaryTaskHeadID = ? ORDER BY OrderIndex", [taskid]) tags = {} linktype = ANIMAL if tasktype == "ANIMAL": linktype = ANIMAL tags = wordprocessor.animal_tags(dbo, animal.get_animal(dbo, int(linkid))) elif tasktype == "PERSON": linktype = PERSON tags = wordprocessor.person_tags(dbo, person.get_person(dbo, int(linkid))) for d in dtd: if d["DAYPIVOT"] == 9999: rollingdate = selecteddate else: rollingdate = i18n.add_days(rollingdate, int(d["DAYPIVOT"])) insert_diary(dbo, username, linktype, int(linkid), rollingdate, \ d["WHOFOR"], \ wordprocessor.substitute_tags(fix(d["SUBJECT"]), tags, True), \ wordprocessor.substitute_tags(fix(d["NOTE"]), tags, True))
def get_treatments_outstanding(dbo, offset="m31", locationfilter=""): """ Returns a recordset of shelter animals awaiting medical treatments: offset is m to go backwards, or p to go forwards with a number of days. ANIMALID, SHELTERCODE, ANIMALNAME, LOCATIONNAME, WEBSITEMEDIANAME, TREATMENTNAME, COST, COMMENTS, NAMEDFREQUENCY, NAMEDNUMBEROFTREATMENTS, NAMEDSTATUS, DOSAGE, STARTDATE, TREATMENTSGIVEN, TREATMENTSREMAINING, TIMINGRULE, TIMINGRULEFREQUENCY, TIMINGRULENOFREQUENCIES, TREATMENTRULE TOTALNUMBEROFTREATMENTS, DATEREQUIRED, DATEGIVEN, TREATMENTCOMMENTS, TREATMENTNUMBER, TOTALTREATMENTS, GIVENBY, REGIMENID, TREATMENTID """ ec = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( subtract_days(now(dbo.timezone), offsetdays)), db.dd(now(dbo.timezone))) if offset.startswith("p"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( now(dbo.timezone)), db.dd(add_days(now(dbo.timezone), offsetdays))) if locationfilter != "": locationfilter = " AND ShelterLocation IN (%s)" % locationfilter return embellish_regimen(dbo.locale, db.query(dbo, "SELECT * FROM v_animalmedicaltreatment " \ "WHERE DateRequired Is Not Null AND DateGiven Is Null " \ "AND Status = 0 " \ "AND DeceasedDate Is Null AND (Archived = 0 OR ActiveMovementType = 2) %s %s " \ "ORDER BY DateRequired, AnimalName" % (ec, locationfilter)))
def auto_update_urgencies(dbo): """ Finds all animals where the next UrgencyUpdateDate field is greater than or equal to today and the urgency is larger than High (so we can never reach Urgent). """ update_period_days = configuration.waiting_list_urgency_update_period(dbo) if update_period_days == 0: al.debug( "urgency update period is 0, not updating waiting list entries", "waitinglist.auto_update_urgencies", dbo) return rows = dbo.query("SELECT a.* " \ "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= ? " \ "AND Urgency > 2", [dbo.today()]) updates = [] for r in rows: al.debug("increasing urgency of waitinglist entry %d" % r.ID, "waitinglist.auto_update_urgencies", dbo) updates.append((now(dbo.timezone), add_days(r.URGENCYUPDATEDATE, update_period_days), r.URGENCY - 1, r.ID)) if len(updates) > 0: dbo.execute_many("UPDATE animalwaitinglist SET " \ "UrgencyLastUpdatedDate=?, " \ "UrgencyUpdateDate=?, " \ "Urgency=? " \ "WHERE ID=? ", updates)
def insert_waitinglist_from_form(dbo, data, username): """ Creates a waiting list record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if utils.df_ks(data, "description") == "": raise utils.ASMValidationError(_("Description cannot be blank", l)) if utils.df_ki(data, "owner") == "0": raise utils.ASMValidationError(_("Waiting list entries must have a contact", l)) if utils.df_ks(data, "dateputon") == "": raise utils.ASMValidationError(_("Date put on cannot be blank", l)) nwlid = db.get_id(dbo, "animalwaitinglist") db.execute(dbo, db.make_insert_user_sql(dbo, "animalwaitinglist", username, ( ( "ID", db.di(nwlid)), ( "SpeciesID", utils.df_s(data, "species")), ( "DatePutOnList", utils.df_d(data, "dateputon", l)), ( "OwnerID", utils.df_s(data, "owner")), ( "AnimalDescription", utils.df_t(data, "description")), ( "ReasonForWantingToPart", utils.df_t(data, "reasonforwantingtopart")), ( "CanAffordDonation", utils.df_c(data, "canafforddonation")), ( "Urgency", utils.df_s(data, "urgency")), ( "DateRemovedFromList", utils.df_d(data, "dateremoved", l)), ( "AutoRemovePolicy", utils.df_s(data, "autoremovepolicy")), ( "DateOfLastOwnerContact", db.dd(now(dbo.timezone))), ( "ReasonForRemoval", utils.df_t(data, "reasonforremoval")), ( "Comments", utils.df_t(data, "comments")), ( "UrgencyLastUpdatedDate", db.dd(now(dbo.timezone))), ( "UrgencyUpdateDate", db.dd(add_days(now(dbo.timezone), configuration.waiting_list_urgency_update_period(dbo)))) ))) audit.create(dbo, username, "animalwaitinglist", str(nwlid)) return nwlid
def execute_diary_task(dbo, username, tasktype, taskid, linkid, selecteddate): """ Runs a diary task tasktype: ANIMAL or PERSON taskid: The ID of the diarytaskhead record to run linkid: The ID of the animal or person to run against selecteddate: If the task has any detail records with a pivot of 0, the date to supply (as python date) """ def fix(s): return s.replace("<", "<").replace(">", ">") rollingdate = i18n.now(dbo.timezone) dtd = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE DiaryTaskHeadID = %d ORDER BY ID" % int(taskid)) tags = {} linktype = ANIMAL if tasktype == "ANIMAL": linktype = ANIMAL tags = wordprocessor.animal_tags(dbo, animal.get_animal(dbo, int(linkid))) elif tasktype == "PERSON": linktype = PERSON tags = wordprocessor.person_tags(dbo, person.get_person(dbo, int(linkid))) for d in dtd: if d["DAYPIVOT"] == 9999: rollingdate = selecteddate else: rollingdate = i18n.add_days(rollingdate, int(d["DAYPIVOT"])) insert_diary(dbo, username, linktype, int(linkid), rollingdate, \ d["WHOFOR"], \ wordprocessor.substitute_tags(fix(d["SUBJECT"]), tags, True), \ wordprocessor.substitute_tags(fix(d["NOTE"]), tags, True))
def get_donations(dbo, offset="m31"): """ Returns a recordset of donations offset is m to go backwards, or p to go forwards with a number of days. ID, DONATIONTYPEID, DONATIONNAME, DATE, DATEDUE, DONATION, ISGIFTAID, FREQUENCY, FREQUENCYNAME, NEXTCREATED, COMMENTS, OWNERNAME, ANIMALNAME, SHELTERCODE, OWNERID, ANIMALID """ ec = "" order = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = "Date >= %s AND Date <= %s" % (db.dd( i18n.subtract_days(i18n.now(dbo.timezone), offsetdays)), db.dd(i18n.now(dbo.timezone))) order = "Date DESC" elif offset.startswith("p"): ec = "Date Is Null AND DateDue >= %s AND DateDue <= %s" % ( db.dd(i18n.now(dbo.timezone)), db.dd(i18n.add_days(i18n.now(dbo.timezone), offsetdays))) order = "DateDue DESC" elif offset.startswith("d"): ec = "Date Is Null AND DateDue <= %s" % (db.dd(i18n.now(dbo.timezone))) order = "DateDue" return db.query(dbo, "SELECT * FROM v_ownerdonation " \ "WHERE %s " "ORDER BY %s" % (ec, order))
def jqm_options_next_month(l): d = now() days = [] for dummy in xrange(0, 31): days.append(jqm_option(python2display(l, d))) d = add_days(d, 1) d = add_months(now(), 3) days.append(jqm_option(python2display(l, d))) d = add_months(now(), 6) days.append(jqm_option(python2display(l, d))) d = add_years(now(), 1) days.append(jqm_option(python2display(l, d))) return "\n".join(days)
def check_create_next_donation(dbo, username, odid): """ Checks to see if a donation is now received and the next in a sequence needs to be created for donations with a frequency """ al.debug("Create next donation %d" % int(odid), "financial.check_create_next_donation", dbo) d = db.query(dbo, "SELECT * FROM ownerdonation WHERE ID = %d" % int(odid)) if d is None or len(d) == 0: al.error("No donation found for %d" % int(odid), "financial.check_create_next_donation", dbo) return d = d[0] # If we have a frequency > 0, the nextcreated flag isn't set # and there's a datereceived and due then we need to create the # next donation in the sequence if d["DATEDUE"] != None and d["DATE"] != None and d["FREQUENCY"] > 0 and d[ "NEXTCREATED"] == 0: nextdue = d["DATEDUE"] if d["FREQUENCY"] == 1: nextdue = i18n.add_days(nextdue, 7) if d["FREQUENCY"] == 2: nextdue = i18n.add_months(nextdue, 1) if d["FREQUENCY"] == 3: nextdue = i18n.add_months(nextdue, 3) if d["FREQUENCY"] == 4: nextdue = i18n.add_years(nextdue, 1) al.debug("Next donation due %s" % str(nextdue), "financial.check_create_next_donation", dbo) # Update nextcreated flag for this donation db.execute( dbo, "UPDATE ownerdonation SET NextCreated = 1 WHERE ID = %d" % int(odid)) # Create the new donation due record did = db.get_id(dbo, "ownerdonation") sql = db.make_insert_user_sql( dbo, "ownerdonation", username, (("ID", db.di(did)), ("AnimalID", db.di(d["ANIMALID"])), ("OwnerID", db.di(d["OWNERID"])), ("MovementID", db.di(d["MOVEMENTID"])), ("DonationTypeID", db.di(d["DONATIONTYPEID"])), ("DateDue", db.dd(nextdue)), ("Date", db.dd(None)), ("Donation", db.di(d["DONATION"])), ("IsGiftAid", db.di(d["ISGIFTAID"])), ("DonationPaymentID", db.di(d["DONATIONPAYMENTID"])), ("Frequency", db.di(d["FREQUENCY"])), ("NextCreated", db.di(0)), ("Comments", db.ds(d["COMMENTS"])))) db.execute(dbo, sql)
def add_message(dbo, createdby, email, message, forname = "*", priority = 0, expires = None, added = None): if added is None: added = now(dbo.timezone) if expires is None: expires = add_days(added, 7) l = dbo.locale mid = db.get_id(dbo, "messages") db.execute(dbo, db.make_insert_sql("messages", ( ( "ID", db.di(mid)), ( "Added", db.dd(added)), ( "Expires", db.dd(expires)), ( "CreatedBy", db.ds(createdby)), ( "Priority", db.di(priority)), ( "ForName", db.ds(forname)), ( "Message", db.ds(message))))) # If email is set, we email the message to everyone that it would match if email == 1: utils.send_user_email(dbo, createdby, forname, _("Message from {0}", l).format(createdby), message) return mid
def now(self, timenow=True, offset=0, settime=""): """ Returns now as a Python date, adjusted for the database timezone. timenow: if True, includes the current time offset: Add this many days to now (negative values supported) settime: A time in HH:MM:SS format to set """ d = i18n.now(self.timezone) if not timenow: d = d.replace(hour = 0, minute = 0, second = 0, microsecond = 0) if offset > 0: d = i18n.add_days(d, offset) if offset < 0: d = i18n.subtract_days(d, abs(offset)) if settime != "": timebits = settime.split(":") d = d.replace(hour = utils.cint(timebits[0]), minute = utils.cint(timebits[1]), second = utils.cint(timebits[2]), microsecond = 0) return d
def check_create_next_donation(dbo, username, odid): """ Checks to see if a donation is now received and the next in a sequence needs to be created for donations with a frequency """ al.debug("Create next donation %d" % int(odid), "financial.check_create_next_donation", dbo) d = db.query(dbo, "SELECT * FROM ownerdonation WHERE ID = %d" % int(odid)) if d is None or len(d) == 0: al.error("No donation found for %d" % int(odid), "financial.check_create_next_donation", dbo) return d = d[0] # If we have a frequency > 0, the nextcreated flag isn't set # and there's a datereceived and due then we need to create the # next donation in the sequence if d["DATEDUE"] != None and d["DATE"] != None and d["FREQUENCY"] > 0 and d["NEXTCREATED"] == 0: nextdue = d["DATEDUE"] if d["FREQUENCY"] == 1: nextdue = i18n.add_days(nextdue, 7) if d["FREQUENCY"] == 2: nextdue = i18n.add_months(nextdue, 1) if d["FREQUENCY"] == 3: nextdue = i18n.add_months(nextdue, 3) if d["FREQUENCY"] == 4: nextdue = i18n.add_years(nextdue, 1) al.debug("Next donation due %s" % str(nextdue), "financial.check_create_next_donation", dbo) # Update nextcreated flag for this donation db.execute(dbo, "UPDATE ownerdonation SET NextCreated = 1 WHERE ID = %d" % int(odid)) # Create the new donation due record did = db.get_id(dbo, "ownerdonation") sql = db.make_insert_user_sql(dbo, "ownerdonation", username, ( ( "ID", db.di(did)), ( "AnimalID", db.di(d["ANIMALID"])), ( "OwnerID", db.di(d["OWNERID"])), ( "MovementID", db.di(d["MOVEMENTID"])), ( "DonationTypeID", db.di(d["DONATIONTYPEID"])), ( "DateDue", db.dd(nextdue)), ( "Date", db.dd(None)), ( "Donation", db.di(d["DONATION"])), ( "IsGiftAid", db.di(d["ISGIFTAID"])), ( "DonationPaymentID", db.di(d["DONATIONPAYMENTID"])), ( "Frequency", db.di(d["FREQUENCY"])), ( "NextCreated", db.di(0)), ( "Comments", db.ds(d["COMMENTS"])) )) db.execute(dbo, sql)
def auto_remove_waitinglist(dbo): """ Finds and automatically marks entries removed that have gone past the last contact date + weeks. """ l = dbo.locale rows = db.query(dbo, "SELECT a.ID, a.DateOfLastOwnerContact, " \ "a.AutoRemovePolicy " \ "FROM animalwaitinglist a WHERE a.DateRemovedFromList Is Null " \ "AND AutoRemovePolicy > 0 AND DateOfLastOwnerContact Is Not Null") updates = [] for r in rows: xdate = add_days(r["DATEOFLASTOWNERCONTACT"], 7 * r["AUTOREMOVEPOLICY"]) if after(now(dbo.timezone), xdate): al.debug("auto removing waitinglist entry %d due to policy" % int(r["ID"]), "waitinglist.auto_remove_waitinglist", dbo) updates.append((now(dbo.timezone), _("Auto removed due to lack of owner contact.", l), r["ID"])) if len(updates) > 0: db.execute_many(dbo, "UPDATE animalwaitinglist SET DateRemovedFromList = %s, " \ "ReasonForRemoval=%s WHERE ID=%s", updates)
def get_tests_outstanding(dbo, offset="m31", locationfilter=""): """ Returns a recordset of animals awaiting tests: offset is m to go backwards, or p to go forwards with a number of days. ID, ANIMALID, SHELTERCODE, ANIMALNAME, LOCATIONNAME, WEBSITEMEDIANAME, DATEREQUIRED, DATEOFTEST, COMMENTS, TESTNAME, RESULTNAME, TESTTYPEID """ ec = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( subtract_days(now(dbo.timezone), offsetdays)), db.dd(now(dbo.timezone))) if offset.startswith("p"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( now(dbo.timezone)), db.dd(add_days(now(dbo.timezone), offsetdays))) if locationfilter != "": locationfilter = " AND ShelterLocation IN (%s)" % locationfilter return db.query(dbo, "SELECT * FROM v_animaltest " \ "WHERE DateRequired Is Not Null AND DateOfTest Is Null " \ "AND DeceasedDate Is Null AND (Archived = 0 OR ActiveMovementType = 2) %s %s " \ "ORDER BY DateRequired, AnimalName" % (ec, locationfilter))
def insert_waitinglist_from_form(dbo, data, username): """ Creates a waiting list record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if utils.df_ks(data, "description") == "": raise utils.ASMValidationError(_("Description cannot be blank", l)) if utils.df_ki(data, "owner") == "0": raise utils.ASMValidationError( _("Waiting list entries must have a contact", l)) if utils.df_ks(data, "dateputon") == "": raise utils.ASMValidationError(_("Date put on cannot be blank", l)) nwlid = db.get_id(dbo, "animalwaitinglist") db.execute( dbo, db.make_insert_user_sql( dbo, "animalwaitinglist", username, (("ID", db.di(nwlid)), ("SpeciesID", utils.df_s(data, "species")), ("DatePutOnList", utils.df_d(data, "dateputon", l)), ("OwnerID", utils.df_s(data, "owner")), ("AnimalDescription", utils.df_t(data, "description")), ("ReasonForWantingToPart", utils.df_t(data, "reasonforwantingtopart")), ("CanAffordDonation", utils.df_c(data, "canafforddonation")), ("Urgency", utils.df_s(data, "urgency")), ("DateRemovedFromList", utils.df_d(data, "dateremoved", l)), ("AutoRemovePolicy", utils.df_s(data, "autoremovepolicy")), ("DateOfLastOwnerContact", db.dd(now(dbo.timezone))), ("ReasonForRemoval", utils.df_t(data, "reasonforremoval")), ("Comments", utils.df_t(data, "comments")), ("UrgencyLastUpdatedDate", db.dd(now(dbo.timezone))), ("UrgencyUpdateDate", db.dd( add_days( now(dbo.timezone), configuration.waiting_list_urgency_update_period(dbo))) )))) audit.create(dbo, username, "animalwaitinglist", str(nwlid)) return nwlid
def add_message(dbo, createdby, email, message, forname="*", priority=0, expires=add_days(now(), 7), added=now()): l = dbo.locale db.execute( dbo, db.make_insert_sql( "messages", (("ID", db.di(db.get_id(dbo, "messages"))), ("Added", db.dd(added)), ("Expires", db.dd(expires)), ("CreatedBy", db.ds(createdby)), ("Priority", db.di(priority)), ("ForName", db.ds(forname)), ("Message", db.ds(message))))) # If email is set, we email the message to everyone that it would match if email == 1: utils.send_user_email(dbo, createdby, forname, _("Message from {0}", l).format(createdby), message)
def get_vaccinations_outstanding(dbo, offset="m31", locationfilter=""): """ Returns a recordset of animals awaiting vaccinations: offset is m to go backwards, or p to go forwards with a number of days. locationfilter is a comma separated list of internal locations to include animals in ID, ANIMALID, SHELTERCODE, ANIMALNAME, LOCATIONNAME, WEBSITEMEDIANAME, DATEREQUIRED, DATEOFVACCINATION, COMMENTS, VACCINATIONTYPE, VACCINATIONID """ ec = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( subtract_days(now(dbo.timezone), offsetdays)), db.dd(now(dbo.timezone))) if offset.startswith("p"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( now(dbo.timezone)), db.dd(add_days(now(dbo.timezone), offsetdays))) if locationfilter != "": locationfilter = " AND ShelterLocation IN (%s)" % locationfilter return db.query(dbo, "SELECT * FROM v_animalvaccination " \ "WHERE DateRequired Is Not Null AND DateOfVaccination Is Null " \ "AND DeceasedDate Is Null AND (Archived = 0 OR ActiveMovementType = 2) %s %s " \ "ORDER BY DateRequired, AnimalName" % (ec, locationfilter))
def auto_remove_waitinglist(dbo): """ Finds and automatically marks entries removed that have gone past the last contact date + weeks. """ l = dbo.locale rows = dbo.query("SELECT a.ID, a.DateOfLastOwnerContact, " \ "a.AutoRemovePolicy " \ "FROM animalwaitinglist a WHERE a.DateRemovedFromList Is Null " \ "AND AutoRemovePolicy > 0 AND DateOfLastOwnerContact Is Not Null") updates = [] for r in rows: xdate = add_days(r.DATEOFLASTOWNERCONTACT, 7 * r.AUTOREMOVEPOLICY) if after(now(dbo.timezone), xdate): al.debug("auto removing waitinglist entry %d due to policy" % r.ID, "waitinglist.auto_remove_waitinglist", dbo) updates.append((now(dbo.timezone), _("Auto removed due to lack of owner contact.", l), r.ID)) if len(updates) > 0: dbo.execute_many("UPDATE animalwaitinglist SET DateRemovedFromList = ?, " \ "ReasonForRemoval=? WHERE ID=?", updates)
def reschedule_vaccination(dbo, username, vaccinationid, newdays): """ Marks a vaccination completed today (if it's not already completed) and reschedules it for given + newdays onwards. """ av = db.query(dbo, "SELECT * FROM animalvaccination WHERE ID = %d" % int(vaccinationid))[0] given = av["DATEOFVACCINATION"] if given is None: given = now(dbo.timezone) db.execute(dbo, "UPDATE animalvaccination SET DateOfVaccination = %s WHERE ID = %d" % ( db.dd(now(dbo.timezone)), int(vaccinationid))) audit.edit(dbo, username, "animalvaccination", str(vaccinationid) + " => given") nvaccid = db.get_id(dbo, "animalvaccination") db.execute(dbo, db.make_insert_user_sql(dbo, "animalvaccination", username, ( ( "ID", db.di(nvaccid)), ( "AnimalID", db.di(av["ANIMALID"])), ( "VaccinationID", db.di(av["VACCINATIONID"])), ( "DateOfVaccination", db.dd(None)), ( "DateRequired", db.dd(add_days(given, int(newdays)))), ( "Cost", db.di(av["COST"])), ( "Comments", db.ds(av["COMMENTS"]))))) audit.create(dbo, username, "animalvaccination", str(nvaccid))
def auto_update_urgencies(dbo): """ Finds all animals where the next UrgencyUpdateDate field is greater than or equal to today and the urgency is larger than High (so we can never reach Urgent). """ update_period_days = configuration.waiting_list_urgency_update_period(dbo) if update_period_days == 0: al.debug("urgency update period is 0, not updating waiting list entries", "waitinglist.auto_update_urgencies", dbo) return rows = db.query(dbo, "SELECT a.* " \ "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= %s " \ "AND Urgency > 2" % db.dd(now(dbo.timezone))) updates = [] for r in rows: al.debug("increasing urgency of waitinglist entry %d" % int(r["ID"]), "waitinglist.auto_update_urgencies", dbo) updates.append((now(dbo.timezone), add_days(r["URGENCYUPDATEDATE"], update_period_days), r["URGENCY"] - 1, r["ID"])) if len(updates) > 0: db.execute_many(dbo, "UPDATE animalwaitinglist SET " \ "UrgencyLastUpdatedDate=%s, " \ "UrgencyUpdateDate=%s, " \ "Urgency=%s " \ "WHERE ID=%s ", updates)
def get_tests_outstanding(dbo, offset = "m31", locationfilter = ""): """ Returns a recordset of animals awaiting tests: offset is m to go backwards, or p to go forwards with a number of days. ID, ANIMALID, SHELTERCODE, ANIMALNAME, LOCATIONNAME, WEBSITEMEDIANAME, DATEREQUIRED, DATEOFTEST, COMMENTS, TESTNAME, RESULTNAME, TESTTYPEID """ ec = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( subtract_days(now(dbo.timezone), offsetdays)), db.dd(now(dbo.timezone))) if offset.startswith("p"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd(now(dbo.timezone)), db.dd( add_days(now(dbo.timezone), offsetdays))) if locationfilter != "": locationfilter = " AND ShelterLocation IN (%s)" % locationfilter return db.query(dbo, "SELECT * FROM v_animaltest " \ "WHERE DateRequired Is Not Null AND DateOfTest Is Null " \ "AND DeceasedDate Is Null AND (Archived = 0 OR ActiveMovementType = 2) %s %s " \ "ORDER BY DateRequired, AnimalName" % (ec, locationfilter))
def get_vaccinations_outstanding(dbo, offset = "m31", locationfilter = ""): """ Returns a recordset of animals awaiting vaccinations: offset is m to go backwards, or p to go forwards with a number of days. locationfilter is a comma separated list of internal locations to include animals in ID, ANIMALID, SHELTERCODE, ANIMALNAME, LOCATIONNAME, WEBSITEMEDIANAME, DATEREQUIRED, DATEOFVACCINATION, COMMENTS, VACCINATIONTYPE, VACCINATIONID """ ec = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( subtract_days(now(dbo.timezone), offsetdays)), db.dd(now(dbo.timezone))) if offset.startswith("p"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd(now(dbo.timezone)), db.dd( add_days(now(dbo.timezone), offsetdays))) if locationfilter != "": locationfilter = " AND ShelterLocation IN (%s)" % locationfilter return db.query(dbo, "SELECT * FROM v_animalvaccination " \ "WHERE DateRequired Is Not Null AND DateOfVaccination Is Null " \ "AND DeceasedDate Is Null AND (Archived = 0 OR ActiveMovementType = 2) %s %s " \ "ORDER BY DateRequired, AnimalName" % (ec, locationfilter))
def get_treatments_outstanding(dbo, offset = "m31", locationfilter = ""): """ Returns a recordset of shelter animals awaiting medical treatments: offset is m to go backwards, or p to go forwards with a number of days. ANIMALID, SHELTERCODE, ANIMALNAME, LOCATIONNAME, WEBSITEMEDIANAME, TREATMENTNAME, COST, COMMENTS, NAMEDFREQUENCY, NAMEDNUMBEROFTREATMENTS, NAMEDSTATUS, DOSAGE, STARTDATE, TREATMENTSGIVEN, TREATMENTSREMAINING, TIMINGRULE, TIMINGRULEFREQUENCY, TIMINGRULENOFREQUENCIES, TREATMENTRULE TOTALNUMBEROFTREATMENTS, DATEREQUIRED, DATEGIVEN, TREATMENTCOMMENTS, TREATMENTNUMBER, TOTALTREATMENTS, GIVENBY, REGIMENID, TREATMENTID """ ec = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd( subtract_days(now(dbo.timezone), offsetdays)), db.dd(now(dbo.timezone))) if offset.startswith("p"): ec = " AND DateRequired >= %s AND DateRequired <= %s" % (db.dd(now(dbo.timezone)), db.dd( add_days(now(dbo.timezone), offsetdays))) if locationfilter != "": locationfilter = " AND ShelterLocation IN (%s)" % locationfilter return embellish_regimen(dbo.locale, db.query(dbo, "SELECT * FROM v_animalmedicaltreatment " \ "WHERE DateRequired Is Not Null AND DateGiven Is Null " \ "AND Status = 0 " \ "AND DeceasedDate Is Null AND (Archived = 0 OR ActiveMovementType = 2) %s %s " \ "ORDER BY DateRequired, AnimalName" % (ec, locationfilter)))
def get_donations(dbo, offset = "m31"): """ Returns a recordset of donations offset is m to go backwards, or p to go forwards with a number of days. ID, DONATIONTYPEID, DONATIONNAME, DATE, DATEDUE, DONATION, ISGIFTAID, FREQUENCY, FREQUENCYNAME, NEXTCREATED, COMMENTS, OWNERNAME, ANIMALNAME, SHELTERCODE, OWNERID, ANIMALID """ ec = "" order = "" offsetdays = utils.cint(offset[1:]) if offset.startswith("m"): ec = "Date >= %s AND Date <= %s" % (db.dd( i18n.subtract_days(i18n.now(dbo.timezone), offsetdays)), db.dd(i18n.now(dbo.timezone))) order = "Date DESC" elif offset.startswith("p"): ec = "Date Is Null AND DateDue >= %s AND DateDue <= %s" % (db.dd(i18n.now(dbo.timezone)), db.dd(i18n.add_days(i18n.now(dbo.timezone), offsetdays))) order = "DateDue DESC" elif offset.startswith("d"): ec = "Date Is Null AND DateDue <= %s" % (db.dd(i18n.now(dbo.timezone))) order = "DateDue" return db.query(dbo, "SELECT * FROM v_ownerdonation " \ "WHERE %s " "ORDER BY %s" % (ec, order))