def test_get_vaccinations(self): medical.get_vaccinations(base.get_dbo(), 1)
def run(self): self.log("Maddies Fund Publisher starting...") BATCH_SIZE = 250 # How many animals to send in one POST PERIOD = 214 # How many days to go back when checking for fosters and adoptions (7 months * 30.5 = 214 days) if self.isPublisherExecuting(): return self.updatePublisherProgress(0) self.setLastError("") self.setStartPublishing() username = configuration.maddies_fund_username(self.dbo) password = configuration.maddies_fund_password(self.dbo) organisation = configuration.organisation(self.dbo) if username == "" or password == "": self.setLastError( "username and password all need to be set for Maddies Fund Publisher" ) self.cleanup() return # Send all fosters and adoptions for the period that haven't been sent since they last had a change. # (we use lastchangeddate instead of sent date because MPA want an update when a number of key # animal fields change, such as neuter status, microchip info, rabies tag, etc) cutoff = i18n.subtract_days(i18n.now(self.dbo.timezone), PERIOD) sql = "%s WHERE a.ActiveMovementType IN (1,2) " \ "AND a.ActiveMovementDate >= ? AND a.DeceasedDate Is Null AND a.NonShelterAnimal = 0 " \ "AND NOT EXISTS(SELECT AnimalID FROM animalpublished WHERE AnimalID = a.ID AND PublishedTo = 'maddiesfund' AND SentDate >= %s) " \ "ORDER BY a.ID" % (animal.get_animal_query(self.dbo), self.dbo.sql_greatest(["a.ActiveMovementDate", "a.LastChangedDate"])) animals = self.dbo.query(sql, [cutoff], distincton="ID") # Now find animals who have been sent previously and are now deceased (using sent date against deceased to prevent re-sends) sql = "%s WHERE a.DeceasedDate Is Not Null AND a.DeceasedDate >= ? AND " \ "EXISTS(SELECT AnimalID FROM animalpublished WHERE AnimalID = a.ID AND " \ "PublishedTo = 'maddiesfund' AND SentDate < a.DeceasedDate)" % animal.get_animal_query(self.dbo) animals += self.dbo.query(sql, [cutoff], distincton="ID") # Now find shelter animals who have been sent previously and are back (using sent date against return to prevent re-sends) sql = "%s WHERE a.Archived = 0 AND " \ "EXISTS(SELECT AnimalID FROM animalpublished WHERE AnimalID = a.ID AND " \ "PublishedTo = 'maddiesfund' AND SentDate < " \ "(SELECT MAX(ReturnDate) FROM adoption WHERE AnimalID = a.ID AND MovementType IN (1,2) AND ReturnDate Is Not Null))" % animal.get_animal_query(self.dbo) animals += self.dbo.query(sql, distincton="ID") # Now find animals who have been sent previously and have a new/changed vaccination since then sql = "%s WHERE a.Archived = 0 AND " \ "EXISTS(SELECT p.AnimalID FROM animalpublished p INNER JOIN animalvaccination av ON av.AnimalID = a.ID WHERE p.AnimalID = a.ID AND " \ "p.PublishedTo = 'maddiesfund' AND (p.SentDate < av.CreatedDate OR p.SentDate < av.LastChangedDate))" % animal.get_animal_query(self.dbo) animals += self.dbo.query(sql, [cutoff], distincton="ID") if len(animals) == 0: self.setLastError("No animals found to publish.") return # Get an authentication token token = "" try: fields = { "username": username, "password": password, "grant_type": "password" } r = utils.post_form(MADDIES_FUND_TOKEN_URL, fields) token = utils.json_parse(r["response"])["access_token"] self.log("got access token: %s (%s)" % (token, r["response"])) except Exception as err: self.setLastError( "failed to get access token: %s (request: '%s') (response: '%s')" % (err, r["requestbody"], r["response"])) self.cleanup() return anCount = 0 thisbatch = [] processed = [] for an in animals: try: anCount += 1 self.log("Processing: %s: %s (%d of %d)" % (an["SHELTERCODE"], an["ANIMALNAME"], anCount, len(animals))) self.updatePublisherProgress( self.getProgress(anCount, len(animals))) # If the user cancelled, stop now if self.shouldStopPublishing(): self.log("User cancelled publish. Stopping.") self.resetPublisherProgress() return # Build an adoption JSON object containing the adopter and animal a = { "PetID": an["ID"], "PetCode": an["SHELTERCODE"], "Site": organisation, "PetName": an["ANIMALNAME"], "PetStatus": self.getPetStatus(an), "PetLitterID": an["ACCEPTANCENUMBER"], "GroupType": utils.iif( utils.nulltostr(an["ACCEPTANCENUMBER"]) != "", "Litter", ""), "PetSpecies": an["SPECIESNAME"], "PetSex": an["SEXNAME"], "DateofBirth": self.getDate(an["DATEOFBIRTH"]), "SpayNeuterStatus": utils.iif(an["NEUTERED"] == 1, "Spayed/Neutered", ""), "Breed": an["BREEDNAME"], "Color": an["BASECOLOURNAME"], "SecondaryColor": "", "Pattern": "", "HealthStatus": an["ASILOMARINTAKECATEGORY"] + 1, # We're zero based, they use 1-base "PetBiography": an["ANIMALCOMMENTS"], "Photo": "%s?method=animal_image&account=%s&animalid=%s" % (SERVICE_URL, self.dbo.database, an["ID"]), "Microchip": an["IDENTICHIPNUMBER"], "MicrochipIssuer": lookups.get_microchip_manufacturer(self.dbo.locale, an["IDENTICHIPNUMBER"]), "RelationshipType": self.getRelationshipType(an), "FosterCareDate": self.getDate(an["ACTIVEMOVEMENTDATE"]), "FosterEndDate": "", "RabiesTag": an["RABIESTAG"], "ID": an["CURRENTOWNERID"], "Firstname": an["CURRENTOWNERFORENAMES"], "Lastname": an["CURRENTOWNERSURNAME"], "EmailAddress": self.getEmail(an["CURRENTOWNEREMAILADDRESS"]), "Street": an["CURRENTOWNERADDRESS"], "Apartment": "", "City": an["CURRENTOWNERTOWN"], "State": an["CURRENTOWNERCOUNTY"], "Zipcode": an["CURRENTOWNERPOSTCODE"], "ContactNumber": an["CURRENTOWNERHOMETELEPHONE"], "Organization": organisation, } # Build a list of intake histories - use the initial one first ph = [{ "IntakeType": an["ENTRYREASONNAME"], "IntakeDate": self.getDate(an["DATEBROUGHTIN"]), "City": utils.nulltostr(an["BROUGHTINBYOWNERTOWN"]), "State": utils.nulltostr(an["BROUGHTINBYOWNERCOUNTY"]), "LengthOwned": "" }] # Then any exit movements where the animal was returned for ra in movement.get_animal_movements(self.dbo, an["ID"]): if ra["MOVEMENTTYPE"] > 0 and ra["MOVEMENTTYPE"] not in ( 2, 8) and ra["RETURNDATE"] is not None: ph.append({ "IntakeType": ra["RETURNEDREASONNAME"], "IntakeDate": self.getDate(ra["RETURNDATE"]), "City": utils.nulltostr(ra["OWNERTOWN"]), "State": utils.nulltostr(ra["OWNERCOUNTY"]), "LengthOwned": "" # We don't have this info }) a["PetHistoryDetails"] = ph # Next add vaccination histories vh = [] for v in medical.get_vaccinations(self.dbo, an["ID"]): vh.append({ "VaccinationRecordNumber": str(v["ID"]), "VaccinationStatus": utils.iif(v["DATEOFVACCINATION"] is not None, "Completed", "Scheduled"), "VaccinationStatusDateTime": self.getDate(v["DATEREQUIRED"]), "Vaccine": v["VACCINATIONTYPE"], "Type": "", # Live/Killed - we don't keep this info yet, see issue #281 "Manufacturer": utils.nulltostr(v["MANUFACTURER"]), "VaccineLot": utils.nulltostr(v["BATCHNUMBER"]), "VaccinationNotes": v["COMMENTS"], "Length": "", # Not sure what this value is for - advised to ignore by MPA devs "RevaccinationDate": self.getDate(v["DATEEXPIRES"]) }) a["PetVaccinationDetails"] = vh thisbatch.append(a) processed.append(an) self.logSuccess("Processed: %s: %s (%d of %d)" % (an["SHELTERCODE"], an["ANIMALNAME"], anCount, len(animals))) # If we have hit our batch size, or this is the # last animal then send what we have. if len(thisbatch) == BATCH_SIZE or anCount == len(animals): j = utils.json({"Animals": thisbatch}) headers = {"Authorization": "Bearer %s" % token} self.log( "HTTP POST request %s: headers: '%s', body: '%s'" % (MADDIES_FUND_UPLOAD_URL, headers, j)) r = utils.post_json(MADDIES_FUND_UPLOAD_URL, j, headers) if r["status"] != 200: self.logError("HTTP %d response: %s" % (r["status"], r["response"])) else: self.log("HTTP %d response: %s" % (r["status"], r["response"])) self.markAnimalsPublished(processed) # start counting again thisbatch = [] processed = [] except Exception as err: self.logError( "Failed processing animal: %s, %s" % (an["SHELTERCODE"], err), sys.exc_info()) self.cleanup()
def csvexport_animals(dbo, dataset, animalids = "", includephoto = False): """ Export CSV data for a set of animals. dataset: The named set of data to use animalids: If dataset == selshelter, a comma separated list of animals to export includephoto: Output a base64 encoded version of the animal's photo if True """ l = dbo.locale q = "" if dataset == "all": q = "SELECT ID FROM animal ORDER BY ID" elif dataset == "shelter": q = "SELECT ID FROM animal WHERE Archived=0 ORDER BY ID" elif dataset == "nonshelter": q = "SELECT ID FROM animal WHERE NonShelterAnimal=1 ORDER BY ID" elif dataset == "selshelter": q = "SELECT ID FROM animal WHERE ID IN (%s) ORDER BY ID" % animalids ids = dbo.query(q) rows = [] for aid in ids: row = collections.OrderedDict() a = animal.get_animal(dbo, aid.ID) if a is None: continue row["ANIMALCODE"] = a["SHELTERCODE"] row["ANIMALNAME"] = a["ANIMALNAME"] if includephoto: row["ANIMALIMAGE"] = "" if a["WEBSITEIMAGECOUNT"] > 0 and includephoto: mdate, mdata = media.get_image_file_data(dbo, "animal", a["ID"]) row["ANIMALIMAGE"] = "data:image/jpg;base64,%s" % base64.b64encode(mdata) row["ANIMALSEX"] = a["SEXNAME"] row["ANIMALTYPE"] = a["ANIMALTYPENAME"] row["ANIMALCOLOR"] = a["BASECOLOURNAME"] row["ANIMALBREED1"] = a["BREEDNAME1"] row["ANIMALBREED2"] = a["BREEDNAME2"] row["ANIMALDOB"] = i18n.python2display(l, a["DATEOFBIRTH"]) row["ANIMALLOCATION"] = a["SHELTERLOCATIONNAME"] row["ANIMALUNIT"] = a["SHELTERLOCATIONUNIT"] row["ANIMALSPECIES"] = a["SPECIESNAME"] row["ANIMALCOMMENTS"] = a["ANIMALCOMMENTS"] row["ANIMALHIDDENDETAILS"] = a["HIDDENANIMALDETAILS"] row["ANIMALHEALTHPROBLEMS"] = a["HEALTHPROBLEMS"] row["ANIMALMARKINGS"] = a["MARKINGS"] row["ANIMALREASONFORENTRY"] = a["REASONFORENTRY"] row["ANIMALNEUTERED"] = a["NEUTERED"] row["ANIMALNEUTEREDDATE"] = i18n.python2display(l, a["NEUTEREDDATE"]) row["ANIMALMICROCHIP"] = a["IDENTICHIPNUMBER"] row["ANIMALMICROCHIPDATE"] = i18n.python2display(l, a["IDENTICHIPDATE"]) row["ANIMALENTRYDATE"] = i18n.python2display(l, a["DATEBROUGHTIN"]) row["ANIMALDECEASEDDATE"] = i18n.python2display(l, a["DECEASEDDATE"]) row["ANIMALNOTFORADOPTION"] = a["ISNOTAVAILABLEFORADOPTION"] row["ANIMALNONSHELTER"] = a["NONSHELTERANIMAL"] row["ANIMALGOODWITHCATS"] = a["ISGOODWITHCATSNAME"] row["ANIMALGOODWITHDOGS"] = a["ISGOODWITHDOGSNAME"] row["ANIMALGOODWITHKIDS"] = a["ISGOODWITHCHILDRENNAME"] row["ANIMALHOUSETRAINED"] = a["ISHOUSETRAINEDNAME"] row["ORIGINALOWNERTITLE"] = a["ORIGINALOWNERTITLE"] row["ORIGINALOWNERINITIALS"] = a["ORIGINALOWNERINITIALS"] row["ORIGINALOWNERFIRSTNAME"] = a["ORIGINALOWNERFORENAMES"] row["ORIGINALOWNERLASTNAME"] = a["ORIGINALOWNERSURNAME"] row["ORIGINALOWNERADDRESS"] = a["ORIGINALOWNERADDRESS"] row["ORIGINALOWNERCITY"] = a["ORIGINALOWNERTOWN"] row["ORIGINALOWNERSTATE"] = a["ORIGINALOWNERCOUNTY"] row["ORIGINALOWNERZIPCODE"] = a["ORIGINALOWNERPOSTCODE"] row["ORIGINALOWNERHOMEPHONE"] = a["ORIGINALOWNERHOMETELEPHONE"] row["ORIGINALOWNERWORKPHONE"] = a["ORIGINALOWNERWORKTELEPHONE"] row["ORIGINALOWNERCELLPHONE"] = a["ORIGINALOWNERMOBILETELEPHONE"] row["ORIGINALOWNEREMAIL"] = a["ORIGINALOWNEREMAILADDRESS"] row["MOVEMENTTYPE"] = a["ACTIVEMOVEMENTTYPE"] row["MOVEMENTDATE"] = i18n.python2display(l, a["ACTIVEMOVEMENTDATE"]) row["PERSONTITLE"] = a["CURRENTOWNERTITLE"] row["PERSONINITIALS"] = a["CURRENTOWNERINITIALS"] row["PERSONFIRSTNAME"] = a["CURRENTOWNERFORENAMES"] row["PERSONLASTNAME"] = a["CURRENTOWNERSURNAME"] row["PERSONADDRESS"] = a["CURRENTOWNERADDRESS"] row["PERSONCITY"] = a["CURRENTOWNERTOWN"] row["PERSONSTATE"] = a["CURRENTOWNERCOUNTY"] row["PERSONZIPCODE"] = a["CURRENTOWNERPOSTCODE"] row["PERSONFOSTERER"] = a["ACTIVEMOVEMENTTYPE"] == 2 and 1 or 0 row["PERSONHOMEPHONE"] = a["CURRENTOWNERHOMETELEPHONE"] row["PERSONWORKPHONE"] = a["CURRENTOWNERWORKTELEPHONE"] row["PERSONCELLPHONE"] = a["CURRENTOWNERMOBILETELEPHONE"] row["PERSONEMAIL"] = a["CURRENTOWNEREMAILADDRESS"] row["VACCINATIONTYPE"] = "" row["VACCINATIONDUEDATE"] = "" row["VACCINATIONGIVENDATE"] = "" row["VACCINATIONEXPIRESDATE"] = "" row["VACCINATIONMANUFACTURER"] = "" row["VACCINATIONBATCHNUMBER"] = "" row["VACCINATIONCOMMENTS"] = "" row["MEDICALNAME"] = "" row["MEDICALDOSAGE"] = "" row["MEDICALGIVENDATE"] = "" row["MEDICALCOMMENTS"] = "" rows.append(row) for v in medical.get_vaccinations(dbo, a["ID"]): row = collections.OrderedDict() row["VACCINATIONTYPE"] = v["VACCINATIONTYPE"] row["VACCINATIONDUEDATE"] = i18n.python2display(l, v["DATEREQUIRED"]) row["VACCINATIONGIVENDATE"] = i18n.python2display(l, v["DATEOFVACCINATION"]) row["VACCINATIONEXPIRESDATE"] = i18n.python2display(l, v["DATEEXPIRES"]) row["VACCINATIONMANUFACTURER"] = v["MANUFACTURER"] row["VACCINATIONBATCHNUMBER"] = v["BATCHNUMBER"] row["VACCINATIONCOMMENTS"] = v["COMMENTS"] row["ANIMALCODE"] = a["SHELTERCODE"] row["ANIMALNAME"] = a["ANIMALNAME"] rows.append(row) for m in medical.get_regimens(dbo, a["ID"]): row = collections.OrderedDict() row["MEDICALNAME"] = m["TREATMENTNAME"] row["MEDICALDOSAGE"] = m["DOSAGE"] row["MEDICALGIVENDATE"] = i18n.python2display(l, m["STARTDATE"]) row["MEDICALCOMMENTS"] = m["COMMENTS"] row["ANIMALCODE"] = a["SHELTERCODE"] row["ANIMALNAME"] = a["ANIMALNAME"] rows.append(row) del a if len(rows) == 0: return "" keys = rows[0].keys() out = StringIO() dict_writer = csv.DictWriter(out, keys) dict_writer.writeheader() dict_writer.writerows(rows) return out.getvalue()
def handler(dbo, user, locationfilter, post): """ Handles posts from the frontend. Depending on the type we either return more HTML for the javascript to inject, or GO URL to have the controller redirect to URL """ l = dbo.locale homelink = "<a href='mobile' class='ui-btn-right' data-icon='home' data-theme='b'>%s</a>" % _( "Home", l) mode = post["posttype"] pid = post.integer("id") animalid = post.integer("animalid") if mode == "vacc": # We're vaccinating an animal a = animal.get_animal(dbo, animalid) medical.update_vaccination_today(dbo, user, pid) return jqm_page_header("", _("Vaccination Given", l), homelink) + \ jqm_p(_("Vaccination marked as given for {0} - {1}", l).format(a["ANIMALNAME"], a["SHELTERCODE"])) + \ jqm_button("mobile#vacc", _("More Vaccinations", l), "", "false") + \ jqm_page_footer() if mode == "test": # We're performing a test on an animal a = animal.get_animal(dbo, animalid) medical.update_test_today(dbo, user, pid, post.integer("resultid")) return jqm_page_header("", _("Test Performed", l), homelink) + \ jqm_p(_("Test marked as performed for {0} - {1}", l).format(a["ANIMALNAME"], a["SHELTERCODE"])) + \ jqm_button("mobile#test", _("More Tests", l), "", "false") + \ jqm_page_footer() elif mode == "med": # We're treating an animal a = animal.get_animal(dbo, animalid) medical.update_treatment_today(dbo, user, pid) return jqm_page_header("", _("Treatment Given", l), homelink) + \ jqm_p(_("Treatment marked as given for {0} - {1}", l).format(a["ANIMALNAME"], a["SHELTERCODE"])) + \ jqm_button("mobile#med", _("More Medications", l), "", "false") + \ jqm_page_footer() elif mode == "dia": # We're completing a diary task d = diary.get_diary(dbo, pid) if post["on"] == "0": diary.complete_diary_note(dbo, user, pid) return jqm_page_header("", _("Completed", l), homelink) + \ jqm_p(_("Diary note {0} marked completed", l).format(d["SUBJECT"])) + \ jqm_button("mobile#diary", _("More diary notes", l), "", "false") + \ jqm_page_footer() else: diary.rediarise_diary_note(dbo, user, pid, post.date("on")) return jqm_page_header("", _("Rediarised", l), homelink) + \ jqm_p(_("Diary note {0} rediarised for {1}", l).format(d["SUBJECT"], post["on"])) + \ jqm_button("mobile#diary", _("More diary notes", l), "", "false") + \ jqm_page_footer() elif mode == "dianew": # We're adding a diary note diary.insert_diary(dbo, user, 0, 0, post.date("diarydate"), post["diaryfor"], post["subject"], post["note"]) return "GO mobile" elif mode == "message": # We're adding a message lookups.add_message(dbo, user, post.boolean("email"), post["message"], post["forname"], post.integer("priority"), post.date("expires")) return "GO mobile" elif mode == "log": # We're adding a log to an animal a = animal.get_animal(dbo, animalid) log.add_log(dbo, user, log.ANIMAL, animalid, post.integer("logtypeid"), post["logtext"]) return "GO mobile" elif mode == "hc": # We're marking an owner homechecked person.update_pass_homecheck(dbo, user, post.integer("personid"), post["comments"]) return "GO mobile" elif mode == "vsa": # Return a list of the shelter animals h = [] alin = [] h.append(header(l)) h.append(jqm_page_header("", _("Shelter Animals", l), homelink)) an = animal.get_animal_find_simple(dbo, "", "all", 0, locationfilter) for a in an: alin.append( jqm_listitem_link( "mobile_post?posttype=va&id=%d" % a["ID"], "%s - %s (%s %s %s) %s" % (a["CODE"], a["ANIMALNAME"], a["SEXNAME"], a["BREEDNAME"], a["SPECIESNAME"], a["IDENTICHIPNUMBER"]), "animal")) h.append(jqm_list("\n".join(alin), True)) h.append(jqm_page_footer()) h.append("</body></html>") return "\n".join(h) elif mode == "uai": # Upload an animal image media.attach_file_from_form(dbo, user, media.ANIMAL, animalid, post) return "GO mobile_post?posttype=va&id=%d&success=true" % animalid elif mode == "aas": return handler_addanimal(l, homelink, dbo) elif mode == "aa": nid, ncode = animal.insert_animal_from_form(dbo, post, user) return "GO mobile_post?posttype=va&id=%d" % nid elif mode == "va": # Display a page containing the selected animal by id a = animal.get_animal(dbo, pid) af = additional.get_additional_fields(dbo, pid, "animal") diet = animal.get_diets(dbo, pid) vacc = medical.get_vaccinations(dbo, pid) test = medical.get_tests(dbo, pid) med = medical.get_regimens(dbo, pid) logs = log.get_logs(dbo, log.ANIMAL, pid) return handler_viewanimal(l, dbo, a, af, diet, vacc, test, med, logs, homelink, post) elif mode == "st": # Display a page to adjust stock levels for id sl = stock.get_stocklevels(dbo, pid) return handler_stocklocation(l, homelink, lookups.get_stock_location_name(dbo, pid), sl) elif mode == "stu": # Update the stock levels from the posted values stock.stock_take_from_mobile_form(dbo, user, post) return "GO mobile"
def animal_tags(dbo, a): """ Generates a list of tags from an animal result (the deep type from calling animal.get_animal) """ l = dbo.locale displaydob = python2display(l, a["DATEOFBIRTH"]) displayage = a["ANIMALAGE"] estimate = "" if a["ESTIMATEDDOB"] == 1: displaydob = a["AGEGROUP"] displayage = a["AGEGROUP"] estimate = _("estimate", l) tags = { "ANIMALNAME" : a["ANIMALNAME"], "ANIMALTYPENAME" : a["ANIMALTYPENAME"], "BASECOLOURNAME" : a["BASECOLOURNAME"], "BASECOLORNAME" : a["BASECOLOURNAME"], "BREEDNAME" : a["BREEDNAME"], "INTERNALLOCATION" : a["SHELTERLOCATIONNAME"], "LOCATIONUNIT" : a["SHELTERLOCATIONUNIT"], "COATTYPE" : a["COATTYPENAME"], "HEALTHPROBLEMS" : a["HEALTHPROBLEMS"], "ANIMALCREATEDBY" : a["CREATEDBY"], "ANIMALCREATEDDATE" : python2display(l, a["CREATEDDATE"]), "DATEBROUGHTIN" : python2display(l, a["DATEBROUGHTIN"]), "DATEOFBIRTH" : python2display(l, a["DATEOFBIRTH"]), "AGEGROUP" : a["AGEGROUP"], "DISPLAYDOB" : displaydob, "DISPLAYAGE" : displayage, "ESTIMATEDDOB" : estimate, "ANIMALID" : str(a["ID"]), "IDENTICHIPNUMBER" : a["IDENTICHIPNUMBER"], "IDENTICHIPPED" : a["IDENTICHIPPEDNAME"], "IDENTICHIPPEDDATE" : python2display(l, a["IDENTICHIPDATE"]), "MICROCHIPNUMBER" : a["IDENTICHIPNUMBER"], "MICROCHIPPED" : a["IDENTICHIPPEDNAME"], "MICROCHIPDATE" : python2display(l, a["IDENTICHIPDATE"]), "TATTOO" : a["TATTOONAME"], "TATTOODATE" : python2display(l, a["TATTOODATE"]), "TATTOONUMBER" : a["TATTOONUMBER"], "COMBITESTED" : a["COMBITESTEDNAME"], "FIVLTESTED" : a["COMBITESTEDNAME"], "COMBITESTDATE" : python2display(l, a["COMBITESTDATE"]), "FIVLTESTDATE" : python2display(l, a["COMBITESTDATE"]), "COMBITESTRESULT" : a["COMBITESTRESULTNAME"], "FIVTESTRESULT" : a["COMBITESTRESULTNAME"], "FIVRESULT" : a["COMBITESTRESULTNAME"], "FLVTESTRESULT" : a["FLVRESULTNAME"], "FLVRESULT" : a["FLVRESULTNAME"], "HEARTWORMTESTED" : a["HEARTWORMTESTEDNAME"], "HEARTWORMTESTDATE" : python2display(l, a["HEARTWORMTESTDATE"]), "HEARTWORMTESTRESULT" : a["HEARTWORMTESTRESULTNAME"], "HIDDENANIMALDETAILS" : a["HIDDENANIMALDETAILS"], "ANIMALLASTCHANGEDBY" : a["LASTCHANGEDBY"], "ANIMALLASTCHANGEDDATE" : python2display(l, a["LASTCHANGEDDATE"]), "MARKINGS" : a["MARKINGS"], "DECLAWED" : a["DECLAWEDNAME"], "RABIESTAG" : a["RABIESTAG"], "GOODWITHCATS" : a["ISGOODWITHCATSNAME"], "GOODWITHDOGS" : a["ISGOODWITHDOGSNAME"], "GOODWITHCHILDREN" : a["ISGOODWITHCHILDRENNAME"], "HOUSETRAINED" : a["ISHOUSETRAINEDNAME"], "NAMEOFPERSONBROUGHTANIMALIN" : a["BROUGHTINBYOWNERNAME"], "ADDRESSOFPERSONBROUGHTANIMALIN" : a["BROUGHTINBYOWNERADDRESS"], "TOWNOFPERSONBROUGHTANIMALIN" : a["BROUGHTINBYOWNERTOWN"], "COUNTYOFPERSONBROUGHTANIMALIN": a["BROUGHTINBYOWNERCOUNTY"], "POSTCODEOFPERSONBROUGHTIN": a["BROUGHTINBYOWNERPOSTCODE"], "CITYOFPERSONBROUGHTANIMALIN" : a["BROUGHTINBYOWNERTOWN"], "STATEOFPERSONBROUGHTANIMALIN": a["BROUGHTINBYOWNERCOUNTY"], "ZIPCODEOFPERSONBROUGHTIN": a["BROUGHTINBYOWNERPOSTCODE"], "BROUGHTINBYNAME" : a["BROUGHTINBYOWNERNAME"], "BROUGHTINBYADDRESS" : a["BROUGHTINBYOWNERADDRESS"], "BROUGHTINBYTOWN" : a["BROUGHTINBYOWNERTOWN"], "BROUGHTINBYCOUNTY" : a["BROUGHTINBYOWNERCOUNTY"], "BROUGHTINBYPOSTCODE" : a["BROUGHTINBYOWNERPOSTCODE"], "BROUGHTINBYCITY" : a["BROUGHTINBYOWNERTOWN"], "BROUGHTINBYSTATE" : a["BROUGHTINBYOWNERCOUNTY"], "BROUGHTINBYZIPCODE" : a["BROUGHTINBYOWNERPOSTCODE"], "BROUGHTINBYHOMEPHONE" : a["BROUGHTINBYHOMETELEPHONE"], "BROUGHTINBYPHONE" : a["BROUGHTINBYHOMETELEPHONE"], "BROUGHTINBYWORKPHONE" : a["BROUGHTINBYWORKTELEPHONE"], "BROUGHTINBYMOBILEPHONE" : a["BROUGHTINBYMOBILETELEPHONE"], "BROUGHTINBYCELLPHONE" : a["BROUGHTINBYMOBILETELEPHONE"], "BROUGHTINBYEMAIL" : a["BROUGHTINBYEMAILADDRESS"], "NAMEOFOWNERSVET" : a["OWNERSVETNAME"], "NAMEOFCURRENTVET" : a["CURRENTVETNAME"], "HASSPECIALNEEDS" : a["HASSPECIALNEEDSNAME"], "NEUTERED" : a["NEUTEREDNAME"], "FIXED" : a["NEUTEREDNAME"], "ALTERED" : a["NEUTEREDNAME"], "NEUTEREDDATE" : python2display(l, a["NEUTEREDDATE"]), "FIXEDDATE" : python2display(l, a["NEUTEREDDATE"]), "ALTEREDDATE" : python2display(l, a["NEUTEREDDATE"]), "ORIGINALOWNERNAME" : a["ORIGINALOWNERNAME"], "ORIGINALOWNERADDRESS" : a["ORIGINALOWNERADDRESS"], "ORIGINALOWNERTOWN" : a["ORIGINALOWNERTOWN"], "ORIGINALOWNERCOUNTY" : a["ORIGINALOWNERCOUNTY"], "ORIGINALOWNERPOSTCODE" : a["ORIGINALOWNERPOSTCODE"], "ORIGINALOWNERCITY" : a["ORIGINALOWNERTOWN"], "ORIGINALOWNERSTATE" : a["ORIGINALOWNERCOUNTY"], "ORIGINALOWNERZIPCODE" : a["ORIGINALOWNERPOSTCODE"], "ORIGINALOWNERHOMEPHONE" : a["ORIGINALOWNERHOMETELEPHONE"], "ORIGINALOWNERPHONE" : a["ORIGINALOWNERHOMETELEPHONE"], "ORIGINALOWNERWORKPHONE" : a["ORIGINALOWNERWORKTELEPHONE"], "ORIGINALOWNERMOBILEPHONE" : a["ORIGINALOWNERMOBILETELEPHONE"], "ORIGINALOWNERCELLPHONE" : a["ORIGINALOWNERMOBILETELEPHONE"], "ORIGINALOWNEREMAIL" : a["ORIGINALOWNEREMAILADDRESS"], "CURRENTOWNERNAME" : a["CURRENTOWNERNAME"], "CURRENTOWNERADDRESS" : a["CURRENTOWNERADDRESS"], "CURRENTOWNERTOWN" : a["CURRENTOWNERTOWN"], "CURRENTOWNERCOUNTY" : a["CURRENTOWNERCOUNTY"], "CURRENTOWNERPOSTCODE" : a["CURRENTOWNERPOSTCODE"], "CURRENTOWNERCITY" : a["CURRENTOWNERTOWN"], "CURRENTOWNERSTATE" : a["CURRENTOWNERCOUNTY"], "CURRENTOWNERZIPCODE" : a["CURRENTOWNERPOSTCODE"], "CURRENTOWNERHOMEPHONE" : a["CURRENTOWNERHOMETELEPHONE"], "CURRENTOWNERPHONE" : a["CURRENTOWNERHOMETELEPHONE"], "CURRENTOWNERWORKPHONE" : a["CURRENTOWNERWORKTELEPHONE"], "CURRENTOWNERMOBILEPHONE" : a["CURRENTOWNERMOBILETELEPHONE"], "CURRENTOWNERCELLPHONE" : a["CURRENTOWNERMOBILETELEPHONE"], "CURRENTOWNEREMAIL" : a["CURRENTOWNEREMAILADDRESS"], "CURRENTVETNAME" : a["CURRENTVETNAME"], "CURRENTVETADDRESS" : a["CURRENTVETADDRESS"], "CURRENTVETTOWN" : a["CURRENTVETTOWN"], "CURRENTVETCOUNTY" : a["CURRENTVETCOUNTY"], "CURRENTVETPOSTCODE" : a["CURRENTVETPOSTCODE"], "CURRENTVETCITY" : a["CURRENTVETTOWN"], "CURRENTVETSTATE" : a["CURRENTVETCOUNTY"], "CURRENTVETZIPCODE" : a["CURRENTVETPOSTCODE"], "CURRENTVETPHONE" : a["CURRENTVETWORKTELEPHONE"], "OWNERSVETNAME" : a["OWNERSVETNAME"], "OWNERSVETADDRESS" : a["OWNERSVETADDRESS"], "OWNERSVETTOWN" : a["OWNERSVETTOWN"], "OWNERSVETCOUNTY" : a["OWNERSVETCOUNTY"], "OWNERSVETPOSTCODE" : a["OWNERSVETPOSTCODE"], "OWNERSVETCITY" : a["OWNERSVETTOWN"], "OWNERSVETSTATE" : a["OWNERSVETCOUNTY"], "OWNERSVETZIPCODE" : a["OWNERSVETPOSTCODE"], "OWNERSVETPHONE" : a["OWNERSVETWORKTELEPHONE"], "RESERVEDOWNERNAME" : a["RESERVEDOWNERNAME"], "RESERVEDOWNERADDRESS" : a["RESERVEDOWNERADDRESS"], "RESERVEDOWNERTOWN" : a["RESERVEDOWNERTOWN"], "RESERVEDOWNERCOUNTY" : a["RESERVEDOWNERCOUNTY"], "RESERVEDOWNERPOSTCODE" : a["RESERVEDOWNERPOSTCODE"], "RESERVEDOWNERCITY" : a["RESERVEDOWNERTOWN"], "RESERVEDOWNERSTATE" : a["RESERVEDOWNERCOUNTY"], "RESERVEDOWNERZIPCODE" : a["RESERVEDOWNERPOSTCODE"], "RESERVEDOWNERHOMEPHONE" : a["RESERVEDOWNERHOMETELEPHONE"], "RESERVEDOWNERPHONE" : a["RESERVEDOWNERHOMETELEPHONE"], "RESERVEDOWNERWORKPHONE" : a["RESERVEDOWNERWORKTELEPHONE"], "RESERVEDOWNERMOBILEPHONE" : a["RESERVEDOWNERMOBILETELEPHONE"], "RESERVEDOWNERCELLPHONE" : a["RESERVEDOWNERMOBILETELEPHONE"], "RESERVEDOWNEREMAIL" : a["RESERVEDOWNEREMAILADDRESS"], "ENTRYCATEGORY" : a["ENTRYREASONNAME"], "REASONFORENTRY" : a["REASONFORENTRY"], "REASONNOTBROUGHTBYOWNER" : a["REASONNO"], "SEX" : a["SEXNAME"], "SIZE" : a["SIZENAME"], "SPECIESNAME" : a["SPECIESNAME"], "ANIMALCOMMENTS" : a["ANIMALCOMMENTS"], "SHELTERCODE" : a["SHELTERCODE"], "AGE" : a["ANIMALAGE"], "ACCEPTANCENUMBER" : a["ACCEPTANCENUMBER"], "LITTERID" : a["ACCEPTANCENUMBER"], "DECEASEDDATE" : python2display(l, a["DECEASEDDATE"]), "DECEASEDNOTES" : a["PTSREASON"], "DECEASEDCATEGORY" : a["PTSREASONNAME"], "SHORTSHELTERCODE" : a["SHORTCODE"], "MOSTRECENTENTRY" : python2display(l, a["MOSTRECENTENTRYDATE"]), "TIMEONSHELTER" : a["TIMEONSHELTER"], "WEBMEDIAFILENAME" : a["WEBSITEMEDIANAME"], "WEBSITEMEDIANAME" : a["WEBSITEMEDIANAME"], "WEBSITEVIDEOURL" : a["WEBSITEVIDEOURL"], "WEBSITEVIDEONOTES" : a["WEBSITEVIDEONOTES"], "WEBMEDIANOTES" : a["WEBSITEMEDIANOTES"], "WEBSITEMEDIANOTES" : a["WEBSITEMEDIANOTES"], "DOCUMENTIMGLINK" : "<img height=\"200\" src=\"" + html.img_src(a, "animal") + "\" >", "DOCUMENTIMGTHUMBLINK" : "<img src=\"" + html.thumbnail_img_src(a, "animalthumb") + "\" />", "DOCUMENTQRLINK" : "<img src=\"http://chart.apis.google.com/chart?cht=qr&chl=%s&chs=150x150\" />" % (BASE_URL + "/animal?id=%s" % a["ID"]), "ANIMALONSHELTER" : yes_no(l, a["ARCHIVED"] == 0), "ANIMALISRESERVED" : yes_no(l, a["HASACTIVERESERVE"] == 1), "ADOPTIONID" : a["ACTIVEMOVEMENTADOPTIONNUMBER"], "ADOPTIONNUMBER" : a["ACTIVEMOVEMENTADOPTIONNUMBER"], "INSURANCENUMBER" : a["ACTIVEMOVEMENTINSURANCENUMBER"], "RESERVATIONDATE" : python2display(l, a["ACTIVEMOVEMENTRESERVATIONDATE"]), "RETURNDATE" : python2display(l, a["ACTIVEMOVEMENTRETURNDATE"]), "ADOPTIONDATE" : python2display(l, a["ACTIVEMOVEMENTDATE"]), "FOSTEREDDATE" : python2display(l, a["ACTIVEMOVEMENTDATE"]), "TRANSFERDATE" : python2display(l, a["ACTIVEMOVEMENTDATE"]), "MOVEMENTDATE" : python2display(l, a["ACTIVEMOVEMENTDATE"]), "MOVEMENTTYPE" : a["ACTIVEMOVEMENTTYPENAME"], "ADOPTIONDONATION" : format_currency_no_symbol(l, a["ACTIVEMOVEMENTDONATION"]), "ADOPTIONCREATEDBY" : a["ACTIVEMOVEMENTCREATEDBY"], "ADOPTIONCREATEDBYNAME" : a["ACTIVEMOVEMENTCREATEDBYNAME"], "ADOPTIONCREATEDDATE" : python2display(l, a["ACTIVEMOVEMENTCREATEDDATE"]), "ADOPTIONLASTCHANGEDBY" : a["ACTIVEMOVEMENTLASTCHANGEDBY"], "ADOPTIONLASTCHANGEDDATE" : python2display(l, a["ACTIVEMOVEMENTLASTCHANGEDDATE"]) } # Set original owner to be current owner on non-shelter animals if a["NONSHELTERANIMAL"] == 1 and a["ORIGINALOWNERNAME"] is not None and a["ORIGINALOWNERNAME"] != "": tags["CURRENTOWNERNAME"] = a["ORIGINALOWNERNAME"] tags["CURRENTOWNERADDRESS"] = a["ORIGINALOWNERADDRESS"] tags["CURRENTOWNERTOWN"] = a["ORIGINALOWNERTOWN"] tags["CURRENTOWNERCOUNTY"] = a["ORIGINALOWNERCOUNTY"] tags["CURRENTOWNERPOSTCODE"] = a["ORIGINALOWNERPOSTCODE"] tags["CURRENTOWNERCITY"] = a["ORIGINALOWNERTOWN"] tags["CURRENTOWNERSTATE"] = a["ORIGINALOWNERCOUNTY"] tags["CURRENTOWNERZIPCODE"] = a["ORIGINALOWNERPOSTCODE"] tags["CURRENTOWNERHOMEPHONE"] = a["ORIGINALOWNERHOMETELEPHONE"] tags["CURRENTOWNERPHONE"] = a["ORIGINALOWNERHOMETELEPHONE"] tags["CURRENTOWNERWORKPHONE"] = a["ORIGINALOWNERWORKTELEPHONE"] tags["CURRENTOWNERMOBILEPHONE"] = a["ORIGINALOWNERMOBILETELEPHONE"] tags["CURRENTOWNERCELLPHONE"] = a["ORIGINALOWNERMOBILETELEPHONE"] tags["CURRENTOWNEREMAIL"] = a["ORIGINALOWNEREMAILADDRESS"] # If the animal doesn't have a current owner, but does have an open # movement with a future date on it, look up the owner and use that # instead so that we can still generate paperwork for future adoptions. if a["CURRENTOWNERID"] is None or a["CURRENTOWNERID"] == 0: latest = animal.get_latest_movement(dbo, a["ID"]) if latest is not None: p = person.get_person(dbo, latest["OWNERID"]) if p is not None: tags["CURRENTOWNERNAME"] = p["OWNERNAME"] tags["CURRENTOWNERADDRESS"] = p["OWNERADDRESS"] tags["CURRENTOWNERTOWN"] = p["OWNERTOWN"] tags["CURRENTOWNERCOUNTY"] = p["OWNERCOUNTY"] tags["CURRENTOWNERPOSTCODE"] = p["OWNERPOSTCODE"] tags["CURRENTOWNERCITY"] = p["OWNERTOWN"] tags["CURRENTOWNERSTATE"] = p["OWNERCOUNTY"] tags["CURRENTOWNERZIPCODE"] = p["OWNERPOSTCODE"] tags["CURRENTOWNERHOMEPHONE"] = p["HOMETELEPHONE"] tags["CURRENTOWNERPHONE"] = p["HOMETELEPHONE"] tags["CURRENTOWNERWORKPHONE"] = p["WORKTELEPHONE"] tags["CURRENTOWNERMOBILEPHONE"] = p["MOBILETELEPHONE"] tags["CURRENTOWNERCELLPHONE"] = p["MOBILETELEPHONE"] tags["CURRENTOWNEREMAIL"] = p["EMAILADDRESS"] # Additional fields add = additional.get_additional_fields(dbo, int(a["ID"]), "animal") for af in add: val = af["VALUE"] if af["FIELDTYPE"] == additional.YESNO: val = additional_yesno(l, af) if af["FIELDTYPE"] == additional.MONEY: val = format_currency_no_symbol(l, af["VALUE"]) tags[af["FIELDNAME"].upper()] = val include_incomplete = configuration.include_incomplete_medical_doc(dbo) # Vaccinations vaccasc = medical.get_vaccinations(dbo, int(a["ID"]), not include_incomplete) vaccdesc = medical.get_vaccinations(dbo, int(a["ID"]), not include_incomplete, medical.DESCENDING_REQUIRED) for idx in range(1, 101): tags["VACCINATIONNAME" + str(idx)] = "" tags["VACCINATIONREQUIRED" + str(idx)] = "" tags["VACCINATIONGIVEN" + str(idx)] = "" tags["VACCINATIONCOMMENTS" + str(idx)] = "" tags["VACCINATIONDESCRIPTION" + str(idx)] = "" tags["VACCINATIONNAMELAST" + str(idx)] = "" tags["VACCINATIONREQUIREDLAST" + str(idx)] = "" tags["VACCINATIONGIVENLAST" + str(idx)] = "" tags["VACCINATIONCOMMENTSLAST" + str(idx)] = "" tags["VACCINATIONDESCRIPTIONLAST" + str(idx)] = "" idx = 1 for v in vaccasc: tags["VACCINATIONNAME" + str(idx)] = v["VACCINATIONTYPE"] tags["VACCINATIONREQUIRED" + str(idx)] = python2display(l, v["DATEREQUIRED"]) tags["VACCINATIONGIVEN" + str(idx)] = python2display(l, v["DATEOFVACCINATION"]) tags["VACCINATIONCOMMENTS" + str(idx)] = v["COMMENTS"] tags["VACCINATIONDESCRIPTION" + str(idx)] = v["VACCINATIONDESCRIPTION"] idx += 1 idx = 1 uniquetypes = {} recentgiven = {} for v in vaccdesc: tags["VACCINATIONNAMELAST" + str(idx)] = v["VACCINATIONTYPE"] tags["VACCINATIONREQUIREDLAST" + str(idx)] = python2display(l, v["DATEREQUIRED"]) tags["VACCINATIONGIVENLAST" + str(idx)] = python2display(l, v["DATEOFVACCINATION"]) tags["VACCINATIONCOMMENTSLAST" + str(idx)] = v["COMMENTS"] tags["VACCINATIONDESCRIPTIONLAST" + str(idx)] = v["VACCINATIONDESCRIPTION"] idx += 1 # If this is the first of this type of vacc we've seen, make # some keys based on its name. if not uniquetypes.has_key(v["VACCINATIONTYPE"]): vname = v["VACCINATIONTYPE"].upper().replace(" ", "").replace("/", "") uniquetypes[v["VACCINATIONTYPE"]] = v tags["VACCINATIONNAME" + vname] = v["VACCINATIONTYPE"] tags["VACCINATIONREQUIRED" + vname] = python2display(l, v["DATEREQUIRED"]) tags["VACCINATIONGIVEN" + vname] = python2display(l, v["DATEOFVACCINATION"]) tags["VACCINATIONCOMMENTS" + vname] = v["COMMENTS"] tags["VACCINATIONDESCRIPTION" + vname] = v["VACCINATIONDESCRIPTION"] # If this is the first of this type of vacc we've seen that's been given # make some keys based on its name if not recentgiven.has_key(v["VACCINATIONTYPE"]) and v["DATEOFVACCINATION"] is not None: vname = v["VACCINATIONTYPE"].upper().replace(" ", "").replace("/", "") recentgiven[v["VACCINATIONTYPE"]] = v tags["VACCINATIONNAMERECENT" + vname] = v["VACCINATIONTYPE"] tags["VACCINATIONREQUIREDRECENT" + vname] = python2display(l, v["DATEREQUIRED"]) tags["VACCINATIONGIVENRECENT" + vname] = python2display(l, v["DATEOFVACCINATION"]) tags["VACCINATIONCOMMENTSRECENT" + vname] = v["COMMENTS"] tags["VACCINATIONDESCRIPTIONRECENT" + vname] = v["VACCINATIONDESCRIPTION"] # Tests testasc = medical.get_tests(dbo, int(a["ID"]), not include_incomplete) testdesc = medical.get_tests(dbo, int(a["ID"]), not include_incomplete, medical.DESCENDING_REQUIRED) for idx in range(1, 101): tags["TESTNAME" + str(idx)] = "" tags["TESTRESULT" + str(idx)] = "" tags["TESTREQUIRED" + str(idx)] = "" tags["TESTGIVEN" + str(idx)] = "" tags["TESTCOMMENTS" + str(idx)] = "" tags["TESTDESCRIPTION" + str(idx)] = "" tags["TESTNAMELAST" + str(idx)] = "" tags["TESTREQUIREDLAST" + str(idx)] = "" tags["TESTGIVENLAST" + str(idx)] = "" tags["TESTCOMMENTSLAST" + str(idx)] = "" tags["TESTDESCRIPTIONLAST" + str(idx)] = "" idx = 1 for t in testasc: tags["TESTNAME" + str(idx)] = t["TESTNAME"] tags["TESTRESULT" + str(idx)] = t["RESULTNAME"] tags["TESTREQUIRED" + str(idx)] = python2display(l, t["DATEREQUIRED"]) tags["TESTGIVEN" + str(idx)] = python2display(l, t["DATEOFTEST"]) tags["TESTCOMMENTS" + str(idx)] = t["COMMENTS"] tags["TESTDESCRIPTION" + str(idx)] = t["TESTDESCRIPTION"] idx += 1 idx = 1 uniquetypes = {} recentgiven = {} for t in testdesc: tags["TESTNAMELAST" + str(idx)] = t["TESTNAME"] tags["TESTRESULTLAST" + str(idx)] = t["RESULTNAME"] tags["TESTREQUIREDLAST" + str(idx)] = python2display(l, t["DATEREQUIRED"]) tags["TESTGIVENLAST" + str(idx)] = python2display(l, t["DATEOFTEST"]) tags["TESTCOMMENTSLAST" + str(idx)] = t["COMMENTS"] tags["TESTDESCRIPTIONLAST" + str(idx)] = t["TESTDESCRIPTION"] idx += 1 # If this is the first of this type of test we've seen, make # some keys based on its name. if not uniquetypes.has_key(t["TESTNAME"]): tname = t["TESTNAME"].upper().replace(" ", "").replace("/", "") uniquetypes[t["TESTNAME"]] = t tags["TESTNAME" + tname] = t["TESTNAME"] tags["TESTRESULT" + tname] = t["RESULTNAME"] tags["TESTREQUIRED" + tname] = python2display(l, t["DATEREQUIRED"]) tags["TESTGIVEN" + tname] = python2display(l, t["DATEOFTEST"]) tags["TESTCOMMENTS" + tname] = t["COMMENTS"] tags["TESTDESCRIPTION" + tname] = t["TESTDESCRIPTION"] # If this is the first of this type of test we've seen that's been given # make some keys based on its name if not recentgiven.has_key(t["TESTNAME"]) and t["DATEOFTEST"] is not None: tname = t["TESTNAME"].upper().replace(" ", "").replace("/", "") recentgiven[t["TESTNAME"]] = t tags["TESTNAMERECENT" + tname] = t["TESTNAME"] tags["TESTRESULTRECENT" + tname] = t["RESULTNAME"] tags["TESTREQUIREDRECENT" + tname] = python2display(l, t["DATEREQUIRED"]) tags["TESTGIVENRECENT" + tname] = python2display(l, t["DATEOFTEST"]) tags["TESTCOMMENTSRECENT" + tname] = t["COMMENTS"] tags["TESTDESCRIPTIONRECENT" + tname] = t["TESTDESCRIPTION"] # Medical medasc = medical.get_regimens(dbo, int(a["ID"]), not include_incomplete) meddesc = medical.get_regimens(dbo, int(a["ID"]), not include_incomplete, medical.DESCENDING_REQUIRED) for idx in range(1, 101): tags["MEDICALNAME" + str(idx)] = "" tags["MEDICALCOMMENTS" + str(idx)] = "" tags["MEDICALFREQUENCY" + str(idx)] = "" tags["MEDICALNUMBEROFTREATMENTS" + str(idx)] = "" tags["MEDICALSTATUS" + str(idx)] = "" tags["MEDICALDOSAGE" + str(idx)] = "" tags["MEDICALSTARTDATE" + str(idx)] = "" tags["MEDICALTREATMENTSGIVEN" + str(idx)] = "" tags["MEDICALTREATMENTSREMAINING" + str(idx)] = "" tags["MEDICALNAMELAST" + str(idx)] = "" tags["MEDICALCOMMENTSLAST" + str(idx)] = "" tags["MEDICALFREQUENCYLAST" + str(idx)] = "" tags["MEDICALNUMBEROFTREATMENTSLAST" + str(idx)] = "" tags["MEDICALSTATUSLAST" + str(idx)] = "" tags["MEDICALDOSAGELAST" + str(idx)] = "" tags["MEDICALSTARTDATELAST" + str(idx)] = "" tags["MEDICALTREATMENTSGIVENLAST" + str(idx)] = "" tags["MEDICALTREATMENTSREMAININGLAST" + str(idx)] = "" idx = 1 for m in medasc: tags["MEDICALNAME" + str(idx)] = m["TREATMENTNAME"] tags["MEDICALCOMMENTS" + str(idx)] = m["COMMENTS"] tags["MEDICALFREQUENCY" + str(idx)] = m["NAMEDFREQUENCY"] tags["MEDICALNUMBEROFTREATMENTS" + str(idx)] = m["NAMEDNUMBEROFTREATMENTS"] tags["MEDICALSTATUS" + str(idx)] = m["NAMEDSTATUS"] tags["MEDICALDOSAGE" + str(idx)] = m["DOSAGE"] tags["MEDICALSTARTDATE" + str(idx)] = python2display(l, m["STARTDATE"]) tags["MEDICALTREATMENTSGIVEN" + str(idx)] = str(m["TREATMENTSGIVEN"]) tags["MEDICALTREATMENTSREMAINING" + str(idx)] = str(m["TREATMENTSREMAINING"]) idx += 1 idx = 1 uniquetypes = {} recentgiven = {} for m in meddesc: tags["MEDICALNAMELAST" + str(idx)] = m["TREATMENTNAME"] tags["MEDICALCOMMENTSLAST" + str(idx)] = m["COMMENTS"] tags["MEDICALFREQUENCYLAST" + str(idx)] = m["NAMEDFREQUENCY"] tags["MEDICALNUMBEROFTREATMENTSLAST" + str(idx)] = m["NAMEDNUMBEROFTREATMENTS"] tags["MEDICALSTATUSLAST" + str(idx)] = m["NAMEDSTATUS"] tags["MEDICALDOSAGELAST" + str(idx)] = m["DOSAGE"] tags["MEDICALSTARTDATELAST" + str(idx)] = python2display(l, m["STARTDATE"]) tags["MEDICALTREATMENTSGIVENLAST" + str(idx)] = str(m["TREATMENTSGIVEN"]) tags["MEDICALTREATMENTSREMAININGLAST" + str(idx)] = str(m["TREATMENTSREMAINING"]) idx += 1 # If this is the first of this type of med we've seen, make # some keys based on its name. if not uniquetypes.has_key(m["TREATMENTNAME"]): tname = m["TREATMENTNAME"].upper().replace(" ", "").replace("/", "") uniquetypes[m["TREATMENTNAME"]] = m tags["MEDICALNAME" + tname] = m["TREATMENTNAME"] tags["MEDICALCOMMENTS" + tname] = m["COMMENTS"] tags["MEDICALFREQUENCY" + tname] = m["NAMEDFREQUENCY"] tags["MEDICALNUMBEROFTREATMENTS" + tname] = m["NAMEDNUMBEROFTREATMENTS"] tags["MEDICALSTATUS" + tname] = m["NAMEDSTATUS"] tags["MEDICALDOSAGE" + tname] = m["DOSAGE"] tags["MEDICALSTARTDATE" + tname] = python2display(l, m["STARTDATE"]) tags["MEDICALTREATMENTSGIVEN" + tname] = str(m["TREATMENTSGIVEN"]) tags["MEDICALTREATMENTSREMAINING" + tname] = str(m["TREATMENTSREMAINING"]) # If this is the first of this type of med we've seen that's complete if not recentgiven.has_key(m["TREATMENTNAME"]) and m["STATUS"] == 2: tname = m["TREATMENTNAME"].upper().replace(" ", "").replace("/", "") recentgiven[m["TREATMENTNAME"]] = m tags["MEDICALNAMERECENT" + tname] = m["TREATMENTNAME"] tags["MEDICALCOMMENTSRECENT" + tname] = m["COMMENTS"] tags["MEDICALFREQUENCYRECENT" + tname] = m["NAMEDFREQUENCY"] tags["MEDICALNUMBEROFTREATMENTSRECENT" + tname] = m["NAMEDNUMBEROFTREATMENTS"] tags["MEDICALSTATUSRECENT" + tname] = m["NAMEDSTATUS"] tags["MEDICALDOSAGERECENT" + tname] = m["DOSAGE"] tags["MEDICALSTARTDATERECENT" + tname] = python2display(l, m["STARTDATE"]) tags["MEDICALTREATMENTSGIVENRECENT" + tname] = str(m["TREATMENTSGIVEN"]) tags["MEDICALTREATMENTSREMAININGRECENT" + tname] = str(m["TREATMENTSREMAINING"]) # Diet dietasc = animal.get_diets(dbo, int(a["ID"])) dietdesc = animal.get_diets(dbo, int(a["ID"]), animal.DESCENDING) for idx in range(1, 101): tags["DIETNAME" + str(idx)] = "" tags["DIETDESCRIPTION" + str(idx)] = "" tags["DIETDATESTARTED" + str(idx)] = "" tags["DIETCOMMENTS" + str(idx)] = "" tags["DIETNAMELAST" + str(idx)] = "" tags["DIETDESCRIPTIONLAST" + str(idx)] = "" tags["DIETDATESTARTEDLAST" + str(idx)] = "" tags["DIETCOMMENTSLAST" + str(idx)] = "" idx = 1 for d in dietasc: tags["DIETNAME" + str(idx)] = d["DIETNAME"] tags["DIETDESCRIPTION" + str(idx)] = d["DIETDESCRIPTION"] tags["DIETDATESTARTED" + str(idx)] = python2display(l, d["DATESTARTED"]) tags["DIETCOMMENTS" + str(idx)] = d["COMMENTS"] idx += 1 idx = 1 for d in dietdesc: tags["DIETNAMELAST" + str(idx)] = d["DIETNAME"] tags["DIETDESCRIPTIONLAST" + str(idx)] = d["DIETDESCRIPTION"] tags["DIETDATESTARTEDLAST" + str(idx)] = python2display(l, d["DATESTARTED"]) tags["DIETCOMMENTSLAST" + str(idx)] = d["COMMENTS"] idx += 1 # Donations donasc = financial.get_animal_donations(dbo, int(a["ID"])) dondesc = financial.get_animal_donations(dbo, int(a["ID"]), financial.DESCENDING) for idx in range(1, 101): tags["RECEIPTNUM" + str(idx)] = "" tags["DONATIONTYPE" + str(idx)] = "" tags["DONATIONDATE" + str(idx)] = "" tags["DONATIONDATEDUE" + str(idx)] = "" tags["DONATIONAMOUNT" + str(idx)] = "" tags["DONATIONCOMMENTS" + str(idx)] = "" tags["DONATIONGIFTAID" + str(idx)] = "" tags["RECEIPTNUMLAST" + str(idx)] = "" tags["DONATIONTYPELAST" + str(idx)] = "" tags["DONATIONDATELAST" + str(idx)] = "" tags["DONATIONDATEDUELAST" + str(idx)] = "" tags["DONATIONAMOUNTLAST" + str(idx)] = "" tags["DONATIONCOMMENTSLAST" + str(idx)] = "" tags["DONATIONGIFTAIDLAST" + str(idx)] = "" idx = 1 for d in donasc: tags["RECEIPTNUM" + str(idx)] = utils.padleft(d["ID"], 8) tags["DONATIONTYPE" + str(idx)] = d["DONATIONNAME"] tags["DONATIONDATE" + str(idx)] = python2display(l, d["DATE"]) tags["DONATIONDATEDUE" + str(idx)] = python2display(l, d["DATEDUE"]) tags["DONATIONAMOUNT" + str(idx)] = format_currency_no_symbol(l, d["DONATION"]) tags["DONATIONCOMMENTS" + str(idx)] = d["COMMENTS"] tags["DONATIONGIFTAID" + str(idx)] = d["ISGIFTAID"] == 1 and _("Yes", l) or _("No", l) idx = 1 uniquetypes = {} recentrec = {} for d in dondesc: tags["RECEIPTNUMLAST" + str(idx)] = utils.padleft(d["ID"], 8) tags["DONATIONTYPELAST" + str(idx)] = d["DONATIONNAME"] tags["DONATIONDATELAST" + str(idx)] = python2display(l, d["DATE"]) tags["DONATIONDATEDUELAST" + str(idx)] = python2display(l, d["DATEDUE"]) tags["DONATIONAMOUNTLAST" + str(idx)] = format_currency_no_symbol(l, d["DONATION"]) tags["DONATIONCOMMENTSLAST" + str(idx)] = d["COMMENTS"] tags["DONATIONGIFTAIDLAST" + str(idx)] = d["ISGIFTAID"] == 1 and _("Yes", l) or _("No", l) idx += 1 # If this is the first of this type of donation we've seen, make # some keys based on its name. if not uniquetypes.has_key(d["DONATIONNAME"]): dname = d["DONATIONNAME"].upper().replace(" ", "").replace("/", "") uniquetypes[d["DONATIONNAME"]] = d tags["RECEIPTNUM" + dname] = utils.padleft(d["ID"], 8) tags["DONATIONTYPE" + dname] = d["DONATIONNAME"] tags["DONATIONDATE" + dname] = python2display(l, d["DATE"]) tags["DONATIONDATEDUE" + dname] = python2display(l, d["DATEDUE"]) tags["DONATIONAMOUNT" + dname] = format_currency_no_symbol(l, d["DONATION"]) tags["DONATIONCOMMENTS" + dname] = d["COMMENTS"] tags["DONATIONGIFTAID" + dname] = d["ISGIFTAID"] == 1 and _("Yes", l) or _("No", l) # If this is the first of this type of donation we've seen that's received if not recentrec.has_key(d["DONATIONNAME"]) and d["DATE"] is not None: dname = d["DONATIONNAME"].upper().replace(" ", "").replace("/", "") recentrec[d["DONATIONNAME"]] = d tags["RECEIPTNUMRECENT" + dname] = utils.padleft(d["ID"], 8) tags["DONATIONTYPERECENT" + dname] = d["DONATIONNAME"] tags["DONATIONDATERECENT" + dname] = python2display(l, d["DATE"]) tags["DONATIONDATEDUERECENT" + dname] = python2display(l, d["DATEDUE"]) tags["DONATIONAMOUNTRECENT" + dname] = format_currency_no_symbol(l, d["DONATION"]) tags["DONATIONCOMMENTSRECENT" + dname] = d["COMMENTS"] tags["DONATIONGIFTAIDRECENT" + dname] = d["ISGIFTAID"] == 1 and _("Yes", l) or _("No", l) # Logs logasc = log.get_logs(dbo, log.ANIMAL, int(a["ID"]), 0, log.ASCENDING) logdesc = log.get_logs(dbo, log.ANIMAL, int(a["ID"]), 0, log.DESCENDING) for idx in range(1, 101): tags["LOGNAME" + str(idx)] = "" tags["LOGDATE" + str(idx)] = "" tags["LOGCOMMENTS" + str(idx)] = "" tags["LOGNAMELAST" + str(idx)] = "" tags["LOGDATELAST" + str(idx)] = "" tags["LOGCOMMENTSLAST" + str(idx)] = "" idx = 1 for o in logasc: tags["LOGNAME" + str(idx)] = o["LOGTYPENAME"] tags["LOGDATE" + str(idx)] = python2display(l, o["DATE"]) tags["LOGCOMMENTS" + str(idx)] = o["COMMENTS"] idx += 1 idx = 1 uniquetypes = {} recentgiven = {} for o in logdesc: tags["LOGNAMELAST" + str(idx)] = o["LOGTYPENAME"] tags["LOGDATELAST" + str(idx)] = python2display(l, o["DATE"]) tags["LOGCOMMENTSLAST" + str(idx)] = o["COMMENTS"] idx += 1 uniquetypes = {} recentrec = {} # If this is the first of this type of log we've seen, make # some keys based on its name. if not uniquetypes.has_key(o["LOGTYPENAME"]): lname = o["LOGTYPENAME"].upper().replace(" ", "").replace("/", "") uniquetypes[o["LOGTYPENAME"]] = o tags["LOGNAME" + lname] = o["LOGTYPENAME"] tags["LOGDATE" + lname] = python2display(l, o["DATE"]) tags["LOGCOMMENTS" + lname] = o["COMMENTS"] tags["LOGNAMERECENT" + lname] = o["LOGTYPENAME"] tags["LOGDATERECENT" + lname] = python2display(l, o["DATE"]) tags["LOGCOMMENTSRECENT" + lname] = o["COMMENTS"] return tags