#!/usr/bin/python #------------------------------------------------------------------------------ # This utility will connect to the openvpms database and undo a reminder run # that occurred on the specified day import MySQLdb import datetime from dateutil import parser db=MySQLdb.connect('localhost','root','','openvpms') def getDate(): return parser.parse("2013-02-13") def getReminders(d): q=''' select * from acts inner join act_details on act_details.act_id=acts.act_id and act_details.name="lastSent" where arch_short_name="act.patientReminder" and status="IN_PROGRESS" and str_to_date(act_details.value,"%%Y-%%m-%%d")=date("%s") '''%str(d.date()) c=db.cursor() c.execute(q) r=c.fetchall() c.close() return r def processReminders(reminders): c=db.cursor() for r in reminders: act_id=r[0] q='''delete from act_details where act_id=%s and name="lastSent" '''%act_id # print q c.execute(q) q='''update act_details set value=0 where act_id=%s and name="reminderCount" '''%act_id # print q c.execute(q) q='''update acts set description="Reset by rollback tool to 0 sent" where act_id=%s '''%act_id # print q c.execute(q) db.commit() c.close() def main(): try: d=getDate() reminders=getReminders(d) processReminders(reminders) except Exception,ex: print ex if __name__=='__main__': main()