def process_test(animalno, testdate=None, testname="", result=""): """ Process a test record """ if ppa.has_key(animalno): a = ppa[animalno] else: asm.stderr("cannot process test %s, %s, %s, %s - no matching animal" % (animalno, testdate, testname, result)) return at = asm.AnimalTest() animaltests.append(at) at.AnimalID = a.ID if testdate is None: testdate = a.DateBroughtIn at.DateRequired = testdate at.DateOfTest = testdate asmresult = 0 if result == "Negative": asmresult = 1 if result == "Positive": asmresult = 2 at.TestResultID = asmresult + 1 if testname == "Heartworm": a.HeartwormTested = 1 a.HeartwormTestDate = testdate a.HeartwormTestResult = asmresult at.TestTypeID = 3 elif testname == "FIV": a.CombiTested = 1 a.CombiTestDate = testdate a.CombiTestResult = asmresult at.TestTypeID = 1 elif testname == "FELV": a.CombiTested = 1 a.CombiTestDate = testdate a.FLVResult = asmresult at.TestTypeID = 2 else: at.TestTypeID = 1 at.Comments = "Test for %s" % testname
vtype = d["Vaccination %d Type" % x] if vgiven: av = asm.AnimalVaccination() animalvaccinations.append(av) av.AnimalID = a.ID av.VaccinationID = "COALESCE((SELECT ID FROM vaccinationtype WHERE VaccinationType LIKE '%s' LIMIT 1), 1)" % vtype av.DateRequired = vgiven av.DateOfVaccination = vgiven for x in range(1, 9): tperformed = getdate(d["Test %d Performed" % x]) ttype = d["Test %d Type" % x].strip()[0:5] tresult = d["Test %d Result" % x] tcomments = d["Test %d Comments" % x] if tperformed: at = asm.AnimalTest() animaltests.append(at) at.AnimalID = a.ID at.DateRequired = tperformed at.DateOfTest = tperformed at.TestTypeID = "COALESCE((SELECT ID FROM testtype WHERE TestName LIKE '%%%s%%' LIMIT 1), 1)" % ttype asmresult = 0 if tresult == "Negative": asmresult = 1 if tresult == "Positive": asmresult = 2 at.TestResultID = asmresult + 1 at.Comments = tcomments # Now that everything else is done, output stored records for a in animals: print a for at in animaltests: