def update_diags(self): assert self.report_id updated = False curs = db.cursor() try: for td in self.test_diags: for i, c in enumerate(td.counts): diagnosis = TestDiags.diagnoses[i][0] if c: try: td.counts[i] = c = int(c) except ValueError: raise ReportError('%s, %s count must be an integer' % (td.name, diagnosis)) else: td.counts[i] = c = None if c == td.load_counts[i]: continue execute(curs, 'UPDATE lab_diags SET count=%s WHERE' ' report_id=%s AND test=%s AND diagnosis=%s', (c, self.report_id, td.name, diagnosis)) if not curs.rowcount: execute(curs, 'INSERT INTO lab_diags' ' VALUES (%s,%s,%s,%s)', (self.report_id, td.name, diagnosis, c)) updated = True finally: curs.close() if updated: db.commit() self.diag_set_initial()
def update_diags(self): assert self.report_id updated = False curs = db.cursor() try: for td in self.test_diags: for i, c in enumerate(td.counts): diagnosis = TestDiags.diagnoses[i][0] if c: try: td.counts[i] = c = int(c) except ValueError: raise ReportError( '%s, %s count must be an integer' % (td.name, diagnosis)) else: td.counts[i] = c = None if c == td.load_counts[i]: continue execute( curs, 'UPDATE lab_diags SET count=%s WHERE' ' report_id=%s AND test=%s AND diagnosis=%s', (c, self.report_id, td.name, diagnosis)) if not curs.rowcount: execute( curs, 'INSERT INTO lab_diags' ' VALUES (%s,%s,%s,%s)', (self.report_id, td.name, diagnosis, c)) updated = True finally: curs.close() if updated: db.commit() self.diag_set_initial()
def update_totals(self): assert self.report_id updated = False curs = db.cursor() try: for tt in self.test_totals: if tt.count: try: tt.count = int(tt.count) except ValueError: raise ReportError('%s count must be an integer' % tt.label) else: tt.count = None if tt.count == tt.load_count: continue execute(curs, 'UPDATE lab_totals SET count=%s' ' WHERE report_id=%s AND test=%s', (tt.count, self.report_id, tt.name)) if not curs.rowcount: execute(curs, 'INSERT INTO lab_totals VALUES (%s,%s,%s)', (self.report_id, tt.name, tt.count)) updated = True finally: curs.close() if updated: db.commit() self.totals_set_initial()
def update_totals(self): assert self.report_id updated = False curs = db.cursor() try: for tt in self.test_totals: if tt.count: try: tt.count = int(tt.count) except ValueError: raise ReportError('%s count must be an integer' % tt.label) else: tt.count = None if tt.count == tt.load_count: continue execute( curs, 'UPDATE lab_totals SET count=%s' ' WHERE report_id=%s AND test=%s', (tt.count, self.report_id, tt.name)) if not curs.rowcount: execute(curs, 'INSERT INTO lab_totals VALUES (%s,%s,%s)', (self.report_id, tt.name, tt.count)) updated = True finally: curs.close() if updated: db.commit() self.totals_set_initial()
def update_report(self): assert self.report_id if self.__monitor.check(): curs = db.cursor() try: execute(curs, 'UPDATE lab_reports SET completed=%s, notes=%s' ' WHERE report_id=%s', self.completed, self.notes, self.report_id) finally: curs.close() db.commit() self.__monitor.clear()
def update_report(self): assert self.report_id if self.__monitor.check(): curs = db.cursor() try: execute( curs, 'UPDATE lab_reports SET completed=%s, notes=%s' ' WHERE report_id=%s', self.completed, self.notes, self.report_id) finally: curs.close() db.commit() self.__monitor.clear()
def update_positive_cases(self): assert self.report_id curs = db.cursor() try: updated = False for case in self.positive_cases: if case.monitor.check(): case.update(curs, self.report_id) updated = True finally: curs.close() if updated: db.commit() for case in self.positive_cases: case.monitor.clear()
def new(self): self.new_report() db.commit()