def toHtmlRow(self): hash_string = "" for tx_hash in self.tx_hashes: hash_string += "<li>%s</li>" % tx_hash.hash if hash_string: hash_string = "<ul>%s</ul>" % hash_string else: hash_string = _("no treatments") if self.completed == 2: completed = _("Yes") elif self.completed == 1: completed = _("Partially") else: completed = _("No") return ''' <tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr> ''' % (localsettings.ops.get( self.dent), self.number, self.itemcode, self.description, localsettings.formatMoney( self.fee), localsettings.formatMoney(self.ptfee), self.feescale, self.csetype, completed, hash_string)
def toHtml(plandata): ''' returns an HTML table of the patients plandata ''' if not plandata.retrieved: return "There was an error retrieving this information" retarg = '''<html><body><center> <h3>PLAN DETAILS</h3> <table width ="100%" border="1"> ''' retarg += "<tr><td>PLAN TYPE</td><td>%s</td></tr>" % plandata.plantype retarg += "<tr><td>BAND</td><td>%s</td></tr>" % plandata.band retarg += "<tr><td>GROSS CHARGE</td><td>%s</td></tr>" % ( localsettings.formatMoney(plandata.grosschg)) retarg += "<tr><td>DISCOUNT</td><td>%s%</td></tr>" % plandata.discount retarg += "<tr><td>NET CHARGE</td><td>%s</td></tr>" % ( localsettings.formatMoney(plandata.netchg)) retarg += "<tr><td>CATEGORY</td><td>%s</td></tr>" % plandata.catcode retarg += "<tr><td>DATE JOINED</td><td>%s</td></tr>" % plandata.planjoin retarg += \ "<tr><td>REGISTRATION NUMBER</td><td>%s</td></tr>" % plandata.regno retarg += '</table></body></html>' return retarg
def toHtml(plandata): """ returns an HTML table of the patients plandata """ if not plandata.retrieved: return "There was an error retrieving this information" retarg = """<html><body><center> <h3>PLAN DETAILS</h3> <table width ="100%" border="1"> """ retarg += "<tr><td>PLAN TYPE</td><td>%s</td></tr>" % plandata.plantype retarg += "<tr><td>BAND</td><td>%s</td></tr>" % plandata.band retarg += "<tr><td>GROSS CHARGE</td><td>%s</td></tr>" % (localsettings.formatMoney(plandata.grosschg)) retarg += "<tr><td>DISCOUNT</td><td>%s%</td></tr>" % plandata.discount retarg += "<tr><td>NET CHARGE</td><td>%s</td></tr>" % (localsettings.formatMoney(plandata.netchg)) retarg += "<tr><td>CATEGORY</td><td>%s</td></tr>" % plandata.catcode retarg += "<tr><td>DATE JOINED</td><td>%s</td></tr>" % plandata.planjoin retarg += "<tr><td>REGISTRATION NUMBER</td><td>%s</td></tr>" % plandata.regno retarg += "</table></body></html>" return retarg
def get_data(self): rows = daybook.inspect_item(self.daybook_id) if rows == (): html = _("No Information found in estimates for this daybook item") self.adv_widget.disable_fee_updates() else: html = '''<table border="1" width="100%%"> <tr><th>%s</th><th>%s</th><th>%s</th></tr>''' % ( _("Description"), _("Fee"), _("Charge") ) for description, fee, ptfee in rows: self.total_fee += fee self.total_ptfee += ptfee html += '''<tr><td>%s</td> <td align="right">%s</td> <td align="right">%s</td></tr>''' % ( description, localsettings.formatMoney(fee), localsettings.formatMoney(ptfee) ) html += '''<tr><th>%s</th> <th align="right">%s</th><th align="right">%s</th></tr>''' % ( _("TOTAL"), localsettings.formatMoney(self.total_fee), localsettings.formatMoney(self.total_ptfee) ) if self.feesa is not None and self.total_fee != self.feesa: self.feesa_label.setText(_("Fee Differs")) if self.feesb is not None and self.total_ptfee != self.feesb: self.feesb_label.setText(_("Charge Differs")) self.web_view.setHtml(html)
def customEstimate(om_gui, html=""): ''' prints a custom estimate to the patient ''' if om_gui.pt.serialno == 0: om_gui.advise(_("no patient selected"), 1) return if html == "": html = standardletter.getHtml(om_gui.pt) pt_total = 0 ehtml = "<br />%s"% _( "Estimate for your current course of treatment.") ehtml += "<br />"*4 ehtml += '<table width="400">' #separate into NHS and non-NHS items. sorted_ests = {"N":[], "P":[]} for est in estimates.sorted_estimates(om_gui.pt.estimates): if "N" in est.csetype: sorted_ests["N"].append(est) else: sorted_ests["P"].append(est) for type_, description in ( ("N", _("NHS items")), ("P", _("Private items")) ): if sorted_ests[type_]: ehtml += '<tr><td colspan = "3"><b>%s</b></td></tr>'% ( description) for est in sorted_ests[type_]: pt_total += est.ptfee number = est.number item = est.description amount = est.ptfee mult = "" if number > 1: mult = "s" item = item.replace("*", mult) if "^" in item: item = item.replace("^", "") ehtml += '''<tr><td>%s</td><td>%s</td> <td align="right">%s</td></tr>'''% ( number, item, localsettings.formatMoney(amount)) ehtml += _('''<tr><td></td><td><b>TOTAL</b></td> <td align="right"><b>%s</b></td></tr>''')% localsettings.formatMoney(pt_total) ehtml += "</table>" + "<br />"*4 html = html.replace("<br />"*(12), ehtml) html += _('''<p><i>Please note, this estimate may be subject to change if clinical circumstances dictate.</i></p>''') if htmlEditor(om_gui, type="cust Estimate", html=html, version=0): om_gui.pt.addHiddenNote("printed", "cust estimate") om_gui.updateHiddenNotesLabel()
def customEstimate(om_gui, html=""): ''' prints a custom estimate to the patient ''' if om_gui.pt.serialno == 0: om_gui.advise(_("no patient selected"), 1) return if html == "": html = standard_letter.getHtml(om_gui.pt) pt_total = 0 ehtml = "<br />%s" % _( "Estimate for your current course of treatment.") ehtml += "<br />" * 4 ehtml += '<table width="400">' # separate into NHS and non-NHS items. sorted_ests = {"N": [], "P": []} for est in estimates.sorted_estimates(om_gui.pt.estimates): if "N" in est.csetype: sorted_ests["N"].append(est) else: sorted_ests["P"].append(est) for type_, description in (("N", _("NHS items")), ("P", _("Private items"))): if sorted_ests[type_]: ehtml += '<tr><td colspan = "3"><b>%s</b></td></tr>' % ( description) for est in sorted_ests[type_]: pt_total += est.ptfee number = est.number item = est.description amount = est.ptfee mult = "" if number > 1: mult = "s" item = item.replace("*", mult) if "^" in item: item = item.replace("^", "") ehtml += '''<tr> <td>%s</td><td>%s</td><td align="right">%s</td> </tr>''' % ( number, item, localsettings.formatMoney(amount)) ehtml += '''<tr><td></td><td><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( _("TOTAL"), localsettings.formatMoney(pt_total)) ehtml += "</table>" + "<br />" * 4 html = html.replace("<br />" * (12), ehtml) html += '<p><i>%s</i></p>' % _('Please note, this estimate may ' 'be subject to change if clinical ' 'circumstances dictate.') if htmlEditor(om_gui, type_="cust Estimate", html=html, version=0): om_gui.pt.addHiddenNote("printed", "cust estimate") om_gui.updateHiddenNotesLabel()
def printAccountsTable(om_gui): ''' print the table ''' # - set a pointer for readability table = om_gui.ui.accounts_tableWidget rowno = table.rowCount() memo_col = table.columnCount() - 1 if rowno == 0: om_gui.advise(_("Nothing to print - have you loaded the table?"), 1) return() total = 0 html = '''<html><body><table border="1"> <tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th> <th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>''' % (_('Dent'), _('SerialNo'), _('Cset'), _('Name'), _('Status'), _("Last tx"), _('Complete'), _('Amount'), _('Memo')) for row in range(rowno): if row % 2 == 0: html += '<tr bgcolor="#eeeeee">' else: html += '<tr>' for col in (0, 1, 2, 3, 4, 5, 6, 7, memo_col): item = table.item(row, col) if item: if col == 1: html += '<td align="right">%s</td>' % item.text() elif col == 7: money = localsettings.pencify(item.text()) money_str = localsettings.formatMoney(money) html += '<td align="right">%s</td>' % money_str total += money else: html += '<td>%s</td>' % item.text() else: html += '<td> </td>' html += '</tr>\n' html += '''<tr> <td colspan="7" align="right"><b>%s</b></td> <td align="right"><b>%s</b></td><td></td> </tr></table></body></html>''' % (_('TOTAL'), localsettings.formatMoney(total)) myclass = letterprint.letter(html, parent=om_gui) myclass.printpage()
def __init__( self, title, fname, sname, addresslines, postcode, amount, parent=None): self.type = type self.printer = QtGui.QPrinter() self.printer.setPageSize(QtGui.QPrinter.A5) self.pdfprinter = QtGui.QPrinter() self.pdfprinter.setPageSize(QtGui.QPrinter.A5) self.title = title self.fname = fname self.sname = sname self.addresslines = addresslines self.postcode = postcode self.amount = localsettings.formatMoney(amount) self.tone = "A" self.previousCorrespondenceDate = "" self.requireDialog = True self.dialog = QtGui.QPrintDialog(self.printer)
def summary_details(sno, start_date): values = (localsettings.OM_DATE_FORMAT, "%06d" % sno, start_date) db = connect() cursor = db.cursor() cursor.execute(SUMMARY_QUERY, values) rows = cursor.fetchall() cursor.close() claimNo = len(rows) if claimNo == 0: return "No Payments Found" retarg = '<table width="100%" border="1">' retarg += '<tr class="table_header">' for header in HEADERS[:3] + HEADERS[8:]: retarg += "<th>%s</th>" % header retarg += '</tr>' total = 0 for i, row in enumerate(rows): if i % 2 == 0: retarg += '<tr bgcolor="#eeeeee">' else: retarg += '<tr>' # a row is (date,sno,dnt,patient,code,amount) retarg += '<td>%s</td>' % (row[0]) retarg += '<td>%s</td>' % localsettings.ops.get(row[1]) CODE = localsettings.cashbookCodesDict.get(row[2], "UNKNOWN") retarg += '<td>%s</td>' % CODE amt = row[3] retarg += '<td align="right">%s</td>' % localsettings.formatMoney(amt) retarg += '</tr>\n' total += amt retarg += '''<tr class="table_header"> <td colspan="3" align="right"><b>TOTAL</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.formatMoney(total)) retarg += '</table>' return retarg
def summary_details(sno, start_date): values = (localsettings.OM_DATE_FORMAT, "%06d" % sno, start_date) db = connect() cursor = db.cursor() cursor.execute(SUMMARY_QUERY, values) rows = cursor.fetchall() cursor.close() claimNo = len(rows) if claimNo == 0: return "No Payments Found" retarg = '<table width="100%" border="1">' retarg += '<tr class="table_header">' for header in HEADERS[:3] + HEADERS[8:]: retarg += "<th>%s</th>" % header retarg += '</tr>' total = 0 for i, row in enumerate(rows): if i % 2 == 0: retarg += '<tr bgcolor="#eeeeee">' else: retarg += '<tr>' #-- a row is (date,sno,dnt,patient,code,amount) retarg += '<td>%s</td>' % (row[0]) retarg += '<td>%s</td>' % localsettings.ops.get(row[1]) CODE = localsettings.cashbookCodesDict.get(row[2], "UNKNOWN") retarg += '<td>%s</td>' % CODE amt = row[3] retarg += '<td align="right">%s</td>' % localsettings.formatMoney(amt) retarg += '</tr>\n' total += amt retarg += '''<tr class="table_header"> <td colspan="3" align="right"><b>TOTAL</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.formatMoney(total)) retarg += '</table>' return retarg
def printAccountsTable(om_gui): ''' print the table ''' #-- set a pointer for readability table = om_gui.ui.accounts_tableWidget rowno = table.rowCount() if rowno == 0: om_gui.advise(_("Nothing to print - have you loaded the table?"), 1) return() total = 0 html = '<html><body><table border="1">' html += _('''<tr><th>Dent</th><th>SerialNo</th><th>Cset</th> <th>FName</th><th>Sname</th><th>DOB</th><th>Memo</th><th>Last Appt</th> <th>Last Bill</th><th>Type</th><th>Number</th><th>Complete</th> <th>Amount</th></tr>''') for row in range(rowno): if row % 2 == 0: html += '<tr bgcolor="#eeeeee">' else: html += '<tr>' for col in range(13): item = table.item(row, col) if item: if col == 1: html += '<td align="right">%s</td>' % item.text() elif col == 12: money = localsettings.pencify(item.text()) money_str = localsettings.formatMoney(money) html += '<td align="right">%s</td>' % money_str total += money else: html += '<td>%s</td>' % item.text() else: html += '<td> </td>' html += '</tr>\n' html += '<tr><td colspan="11"></td><td><b>' + _('TOTAL') + '''</b></td> <td align="right"><b>%s</b></td></tr></table></body></html>''' % ( localsettings.formatMoney(total)) myclass = letterprint.letter(html) myclass.printpage()
def printAccountsTable(om_gui): ''' print the table ''' #-- set a pointer for readability table = om_gui.ui.accounts_tableWidget rowno = table.rowCount() if rowno == 0: om_gui.advise(_("Nothing to print - have you loaded the table?"), 1) return () total = 0 html = '<html><body><table border="1">' html += _('''<tr><th>Dent</th><th>SerialNo</th><th>Cset</th> <th>FName</th><th>Sname</th><th>DOB</th><th>Memo</th><th>Last Appt</th> <th>Last Bill</th><th>Type</th><th>Number</th><th>Complete</th> <th>Amount</th></tr>''') for row in range(rowno): if row % 2 == 0: html += '<tr bgcolor="#eeeeee">' else: html += '<tr>' for col in range(13): item = table.item(row, col) if item: if col == 1: html += '<td align="right">%s</td>' % item.text() elif col == 12: money = int(float(item.text()) * 100) money_str = localsettings.formatMoney(money) html += '<td align="right">%s</td>' % money_str total += money else: html += '<td>%s</td>' % item.text() else: html += '<td> </td>' html += '</tr>\n' html += '<tr><td colspan="11"></td><td><b>' + _('TOTAL') + '''</b></td> <td align="right"><b>%s</b></td></tr></table></body></html>''' % ( localsettings.formatMoney(total)) myclass = letterprint.letter(html) myclass.printpage()
def updateMoneyTotal(self, arg=0): ''' updates the money label ''' fees = (self.money0_spinBox.value() + self.money1_spinBox.value() + self.money9_spinBox.value() + self.money10_spinBox.value() + self.money11_spinBox.value() - self.money2_spinBox.value() - self.money3_spinBox.value() - self.money8_spinBox.value()) self.total_label.setText(localsettings.formatMoney(fees))
def toHtmlRow(self): hash_string = "" for tx_hash in self.tx_hashes: hash_string += "<li>%s</li>" % tx_hash.hash if hash_string: hash_string = "<ul>%s</ul>" % hash_string else: hash_string = _("no treatments") if self.completed == 2: completed = _("Yes") elif self.completed == 1: completed = _("Partially") else: completed = _("No") return ''' <tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr> ''' % ( localsettings.ops.get(self.dent), self.number, self.itemcode, self.description, localsettings.formatMoney(self.fee), localsettings.formatMoney(self.ptfee), self.feescale, self.csetype, completed, hash_string)
def data(self, column): if column == 0: if self.key != self.parentItem.key: return self.key if self.itemData is None: pass elif column == 1: uc = self.itemData.fee_shortcut_for_display(0) try: if uc == self.parentItem.itemData.usercode: uc = "" if self.itemData.has_fee_shortcuts: uc = self.itemData.fee_shortcut_for_display(self.row() + 1) except AttributeError: pass return uc elif column == 2: desc = self.itemData.description try: if desc == self.parentItem.itemData.description: return "" except AttributeError: return desc elif column == 3: return self.itemData.brief_descriptions[self.myindex] elif column == 4: return localsettings.formatMoney(self.itemData.fees[self.myindex]) elif column == 5: # if self.table.hasPtCols: try: return localsettings.formatMoney( self.itemData.ptFees[self.myindex]) except IndexError: return "error in feescale" return None
def initialMoney(self): ''' loads the money at startup ''' self.ui.total_label.setText(localsettings.formatMoney(self.pt.fees)) self.ui.money1_spinBox.setValue(self.pt.money1) self.ui.money2_spinBox.setValue(self.pt.money2) self.ui.money3_spinBox.setValue(self.pt.money3) self.ui.money4_spinBox.setValue(self.pt.money4) self.ui.money5_spinBox.setValue(self.pt.money5) self.ui.money6_spinBox.setValue(self.pt.money6) self.ui.money7_spinBox.setValue(self.pt.money7) self.ui.money8_spinBox.setValue(self.pt.money8) self.ui.money9_spinBox.setValue(self.pt.money9) self.ui.money10_spinBox.setValue(self.pt.money10) self.ui.money11_spinBox.setValue(self.pt.money11)
def initialMoney(self): ''' loads the money at startup ''' self.ui.total_label.setText( localsettings.formatMoney(self.pt.fees)) self.ui.money1_spinBox.setValue(self.pt.money1) self.ui.money2_spinBox.setValue(self.pt.money2) self.ui.money3_spinBox.setValue(self.pt.money3) self.ui.money4_spinBox.setValue(self.pt.money4) self.ui.money5_spinBox.setValue(self.pt.money5) self.ui.money6_spinBox.setValue(self.pt.money6) self.ui.money7_spinBox.setValue(self.pt.money7) self.ui.money8_spinBox.setValue(self.pt.money8) self.ui.money9_spinBox.setValue(self.pt.money9) self.ui.money10_spinBox.setValue(self.pt.money10) self.ui.money11_spinBox.setValue(self.pt.money11)
def __init__(self, title, fname, sname, addresslines, postcode, amount, parent=None): self.parent = parent self.printer = QtPrintSupport.QPrinter() self.printer.setPaperSize(QtPrintSupport.QPrinter.A5) self.pdfprinter = QtPrintSupport.QPrinter() self.pdfprinter.setPaperSize(QtPrintSupport.QPrinter.A5) self.title = title self.fname = fname self.sname = sname self.addresslines = addresslines self.postcode = postcode self.amount = localsettings.formatMoney(amount) self.tone = "A" self.previousCorrespondenceDate = "" self.requireDialog = True self.sf = SettingsFetcher()
def __init__(self, parent=None): _InputDialog.__init__(self, parent) self.label.setText(_("Please enter the precision you require")) self.spinbox.setPrefix(localsettings.formatMoney(0)[0]) # self.spinbox.setValue(0.10) self.round_down_radio_button = QtGui.QRadioButton(_("round down")) self.round_up_radio_button = QtGui.QRadioButton(_("round up")) self.round_to_nearest_radio_button = QtGui.QRadioButton( _("round up/down to nearest value")) self.round_to_nearest_radio_button.setChecked(True) frame = QtGui.QFrame() layout = QtGui.QVBoxLayout(frame) layout.addWidget(self.round_up_radio_button) layout.addWidget(self.round_down_radio_button) layout.addWidget(self.round_to_nearest_radio_button) self.insertWidget(frame)
def details(sno, current_csno, include_estimates=False, include_daybook=False): ''' returns an html page showing pt's Treatment History along with estimates ''' courses = list(_get_courses(sno, current_csno)) estimates_list = estimatesHistory.getEsts(sno) if include_estimates else [] daybook_list = list(daybook.all_data(sno)) if include_daybook else [] daybook_course_guesses = {} displayed_ests = [] course_checker_errors = 0 html = "<body><html><!-- ERRORS --><!-- ORPHANS --><h2>%s - %d %s</h2>" % ( _("Past Courses of Treatment"), len(courses), _("found") ) if current_csno is not None: html += "<strong>%s %s %s</strong><br />" % ( _("Ignoring course number"), current_csno, _("as this is active") ) days_elapsed = None for i, course in enumerate(courses): course_html = course.to_html(ALLOW_EDIT, days_elapsed) course_ests = [] if include_estimates: est_table_init = False for est in estimates_list: if est.courseno == course.courseno: course_ests.append(est) if not est_table_init: header = est.htmlHeader() if estimatesHistory.ALLOW_EDIT: header = header.replace( "<!--editlink-->", estimatesHistory.EDIT_STRING % est.courseno) course_html += ( '<table width="100%%" border="1">%s ' % header) est_table_init = True course_html += est.toHtmlRow() if est_table_init: course_html += '</table>\n' else: course_html += "%s %d" % (_("no estimate found for courseno"), course.courseno) displayed_ests += course_ests if include_daybook: daybook_html = "" if course.accd is None: accd = datetime.date(1980, 1, 1) course_html += "<em>%s</em><br />" % _( "Warning - No course acceptance date") else: accd = course.accd if course.cmpd is None: cmpd = datetime.date.today() course_html += "<em>%s</em><br />" % _( "Warning - No course completion date, " "using today to gather daybook items.") else: cmpd = course.cmpd for daybook_entry in daybook_list: if accd <= daybook_entry.date <= cmpd: try: daybook_course_guesses[course.courseno].append( daybook_entry) except KeyError: daybook_course_guesses[ course.courseno] = [ daybook_entry] gap = cmpd - daybook_entry.date if daybook.ALLOW_TX_EDITS: id_col = '<a href="om://daybook_id_edit?%s">%s</a>' % ( daybook_entry.id, _("Edit Tx")) else: id_col = str(daybook_entry.id) daybook_html += "<tr><td>%s</td></tr>" % ( "</td><td> ".join( (localsettings.formatDate(daybook_entry.date), daybook_entry.coursetype, localsettings.ops.get(daybook_entry.dntid), localsettings.ops.get(daybook_entry.trtid, "-"), daybook_entry.diagn, daybook_entry.perio, daybook_entry.anaes, daybook_entry.misc, daybook_entry.ndu, daybook_entry.ndl, daybook_entry.odu, daybook_entry.odl, daybook_entry.other, daybook_entry.chart.decode( "utf8").strip(" %s" % chr(0)), localsettings.formatMoney(daybook_entry.feesa), localsettings.formatMoney(daybook_entry.feesb), id_col)) ) if daybook_html: header_rows = daybook.all_data_header() if course.cmpd is None: header_rows = header_rows.replace( "<!--gap-->", _("Course is Ongoing")) elif gap.days != 0: header_rows = header_rows.replace( "<!--gap-->", "%s %s %s" % (_("Course closed"), gap.days, _("days after last treatment"))) course_html += '<table width="100%%" border=1>%s%s</table>' % ( header_rows, daybook_html) else: course_html += "%s<br />" % _( "Course dates not found in daybook") if include_estimates and include_daybook: course_check = CourseChecker( course, course_ests, daybook_course_guesses.get(course.courseno, [])) if course_check.has_errors: course_checker_errors += 1 course_html += course_check.results course_html += '''<br /> <a href="om://consistent_courseno?%s">%s</a>''' % ( course.courseno, _("Examine these Issues.")) days_elapsed = "" try: prev_course = courses[i + 1] if ALLOW_EDIT: merge_link = \ '<br /><a href="om://merge_courses?%s+%s">%s?</a>' % ( course.courseno, prev_course.courseno, _("Merge with previous course") ) course_html = course_html.replace("<!--merge-->", merge_link) days_elapsed = (course.accd - prev_course.cmpd).days except IndexError: days_elapsed = None except TypeError: pass finally: course_html += '<br /><hr /><br />' html += course_html html += "</html></body>" orphaned_html = "" i = 0 for est in estimates_list: if est not in displayed_ests and est.courseno != current_csno: if i == 0: orphaned_html += '''<h1>%s %s</h1> <table width="100%%" border="1">%s ''' % ( _("WARNING"), _("ORPHANED ESTIMATE DATA"), est.htmlHeader().replace("#ffff99", "red") ) orphaned_html += est.toHtmlRow() i += 1 if course_checker_errors: html = html.replace( "<!-- ERRORS -->", "<h3>%d %s</h3>" % (course_checker_errors, _("Errors Found")) ) if i == 0: return html return html.replace("<!-- ORPHANS -->", "%s</table><em>%s</em><br />" % ( orphaned_html, _("This shouldn't happen!")) )
def html(courseno): values = (courseno,) db = connect() cursor = db.cursor() cursor.execute(QUERY, values) rows = cursor.fetchall() cursor.close() est_count = len(rows) if est_count == 0: return "<h2>No Estimate Found</h2>" completed, planned = [], [] for description, fee, comp in rows: if comp: completed.append( (description, fee, localsettings.formatMoney(fee))) else: planned.append((description, fee, localsettings.formatMoney(fee))) n_rows = len(planned) if len(completed) > n_rows: n_rows = len(completed) html_ = ''' <table> <tr> <th colspan="2">Planned</th> <th> </th> <th colspan="2">Completed</th> </tr> ''' c_tot, p_tot = 0, 0 for i in range(n_rows): try: c_desc, fee, c_fee = completed[i] c_tot += fee except IndexError: c_desc, c_fee = "", "" try: p_desc, fee, p_fee = planned[i] p_tot += fee except IndexError: p_desc, p_fee = "", "" html_ += '''<tr> <td width= '30%%'>%s</td> <td width= '20%%' align='right'>%s</td> <td /> <td width= '30%%'>%s</td> <td width= '20%%' align='right'>%s</td> </tr>''' % ( p_desc, p_fee, c_desc, c_fee) html_ += '''<tr> <td colspan="2" align='right'><b>%s</b></td> <td /> <td colspan="2" align='right'><b>%s</b></td> </tr>''' % ( localsettings.formatMoney(p_tot), localsettings.formatMoney(c_tot)) return html_ + "</table><br />"
def details(regdent, trtdent, startdate, enddate, filters=""): ''' returns an html table, for regdent, trtdent,startdate,enddate ''' dent_conditions = "" dents = [] try: if regdent != "*ALL*": dent_conditions = 'dntid=%s and ' dents.append(localsettings.ops_reverse[regdent]) if trtdent != "*ALL*": dent_conditions += 'trtid=%s and ' dents.append(localsettings.ops_reverse[trtdent]) except KeyError: print "Key Error - %s or %s unregconised" % (regdent, trtdent) return '<html><body>%s</body></html>' % _( "Error - unrecognised practioner- sorry") total, nettotal = 0, 0 iterDate = QDate(startdate.year(), startdate.month(), 1) retarg = ''' <html><body><h4>%s %s %s %s %s %s %s %s %s</h4>''' % ( _("Patients of"), regdent, _("treated by"), trtdent, _("between"), localsettings.formatDate(startdate.toPyDate()), _("and"), localsettings.formatDate(enddate.toPyDate()), filters) retarg += '''<table width="100%" border="1"><tr><th>DATE</th> <th>Dents</th><th>Serial Number</th><th>Name</th> <th>Pt Type</th><th>Treatment</th><th></th> <th>Gross Fee</th><th>Net Fee</th>''' db = connect.connect() cursor = db.cursor() query = DETAILS_QUERY.replace("{{DENT CONDITIONS}}", dent_conditions) query = query.replace("{{FILTERS}}", filters) while enddate >= iterDate: monthtotal, monthnettotal = 0, 0 if startdate > iterDate: queryStartDate = startdate else: queryStartDate = iterDate queryEndDate = iterDate.addMonths(1).addDays(-1) if enddate < queryEndDate: queryEndDate = enddate values = tuple( dents + [queryStartDate.toPyDate(), queryEndDate.toPyDate()]) cursor.execute(query, (values)) rows = cursor.fetchall() for i, row in enumerate(rows): retarg += '<tr>' if i % 2 else '<tr bgcolor="#eeeeee">' retarg += "<td>%s</td>" % row[0] try: retarg += '<td> %s / ' % localsettings.ops[row[4]] except KeyError: retarg += "<td>?? / " try: retarg += localsettings.ops[row[5]] except KeyError: retarg += "??" retarg += '</td><td>%s</td><td>%s</td><td>%s</td>' % (row[1:4]) tx = "" for item in (6, 7, 8, 9, 10, 11, 12, 13, 14, 15): if row[item] is not None and row[item] != "": tx += "%s " % row[item] if ALLOW_TX_EDITS: extra_link = ' / <a href="daybook_id_edit?%s">%s</a>' % ( row[19], _("Edit Tx")) else: extra_link = "" retarg += '''<td>%s</td> <td><a href="daybook_id?%sfeesa=%sfeesb=%s">%s</a>%s</td> <td align="right">%s</td> <td align="right">%s</td></tr>''' % (tx.strip("%s " % chr(0)), row[19], row[16], row[17], _("Ests"), extra_link, localsettings.formatMoney( row[16]), localsettings.formatMoney(row[17])) total += int(row[16]) monthtotal += int(row[16]) nettotal += int(row[17]) monthnettotal += int(row[17]) retarg += '''<tr><td colspan="6"></td><td><b>SUBTOTAL - %s %s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.monthName(iterDate.toPyDate()), iterDate.year(), localsettings.formatMoney(monthtotal), localsettings.formatMoney(monthnettotal)) iterDate = iterDate.addMonths(1) cursor.close() # db.close() retarg += '''<tr><td colspan="6"></td><td><b>GRAND TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr></table></body></html>''' % ( localsettings.formatMoney(total), localsettings.formatMoney(nettotal)) return retarg
def details(sno): ''' returns an html page showing pt's payment History ''' values = (localsettings.OM_DATE_FORMAT, "%06d" % sno) db = connect() cursor = db.cursor() cursor.execute(QUERY, values) rows = cursor.fetchall() cursor.close() claimNo = len(rows) if claimNo == 0: return "<h2>No Payments Found</h2>" retarg = '<html><body><table width="100%" border="1">' retarg += '<tr>' for header in HEADERS: retarg += "<th>%s</th>" % header retarg += '</tr>' odd = True total, cashTOT, chequeTOT, cardTOT, otherTOT = 0, 0, 0, 0, 0 for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True # a row is (date,sno,dnt,patient,code,amount) retarg += '<td>%s</td>' % (row[0]) retarg += '<td>%s</td>' % localsettings.ops.get(row[1]) retarg += '<td>%s</td>' % row[2] CODE = localsettings.cashbookCodesDict.get(row[3], "UNKNOWN") retarg += '<td>%s</td>' % CODE amt = row[4] amt_str = localsettings.formatMoney(amt) if "CASH" in CODE: retarg += '<td align="right">%s</td>' % amt_str cashTOT += amt retarg += "<td> </td>" * 3 elif "CHEQUE" in CODE: retarg += '<td> </td><td align="right">%s</td>' % amt_str chequeTOT += amt retarg += "<td> </td>" * 2 elif "CARD" in CODE: retarg += "<td> </td>" * 2 retarg += '<td align="right">%s</td>' % amt_str cardTOT += amt retarg += "<td> </td>" else: retarg += "<td> </td>" * 3 retarg += '<td align="right">%s</td>' % amt_str otherTOT += amt retarg += '<td align="right">%s</td>' % amt_str retarg += '</tr>\n' total += amt retarg += '''<tr><td colspan="3"></td> <td><b>TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.formatMoney(cashTOT), localsettings.formatMoney(chequeTOT), localsettings.formatMoney(cardTOT), localsettings.formatMoney(otherTOT), localsettings.formatMoney(total)) retarg += '</table></body></html>' return retarg
def details(pt, Saved=True): '''returns an html set showing pt name etc...''' try: retarg = header(pt) + '<hr />' if "N" in pt.cset: retarg += '''<img src="%s/nhs_scot.png" alt="NHS" /> <br />''' % localsettings.resources_path if pt.exemption != "": retarg += " exemption=%s" % str(pt.exemption) else: retarg += "NOT EXEMPT" retarg += "<br />" elif "I" in pt.cset: retarg += '''<img src="%s/hdp_small.png" alt="HDP" /> <br />''' % localsettings.resources_path elif "P" in pt.cset: retarg += '''<img src="%s/private.png" alt="PRIVATE" /> <br />''' % localsettings.resources_path else: retarg += 'UNKNOWN COURSETYPE = %s <br />' % str(pt.cset) retarg += "%s<br />" % pt.fee_table.briefName try: retarg += 'dentist = %s' % localsettings.ops[pt.dnt1] if pt.dnt2 != 0 and pt.dnt1 != pt.dnt2: retarg += '/%s' % localsettings.ops[pt.dnt2] except KeyError as e: retarg += '<h4>Please Set a Dentist for this patient!</h4><hr />' if pt.memo != '': retarg += '<h4>Memo</h4>%s<hr />' % pt.memo retarg += '''<table border="1">' <tr><td>Last IO Xrays</td><td>%s</td></tr> <tr><td>Last OPG</td><td>%s</td></tr> <tr><td>Last Sp</td><td>%s</td></tr> ''' % (localsettings.formatDate( pt.pd9), localsettings.formatDate( pt.pd8), localsettings.formatDate(pt.pd10)) letype = "" lastexam = datetime.date(1, 1, 1) i = 0 for date in (pt.pd5, pt.pd6, pt.pd7): if date and date > lastexam: lastexam = date letype = ("(CE)", "(ECE)", "(FCA)")[i] i += 1 if lastexam == datetime.date(1, 1, 1): lastexam = None if letype != "": retarg += '<tr><td>Last Exam %s</td><td>%s</td></tr>' % ( letype, localsettings.formatDate(lastexam)) if pt.recall_active: retarg += '''<tr><td>Recall Date</td><td>%s</td></tr> </table>''' % localsettings.formatDate(pt.recd) else: retarg += '<tr><td colspan="2">%s</td></tr></table>' % _( "DO NOT RECALL") if not Saved: alert = "<br />NOT SAVED" else: alert = "" if pt.fees > 0: amount = localsettings.formatMoney(pt.fees) retarg += '<hr /><h3 class="debt">Account = %s %s</h3>' % (amount, alert) if pt.fees < 0: amount = localsettings.formatMoney(-pt.fees) retarg += '<hr /><h3>%s in credit %s</h3>' % (amount, alert) if pt.underTreatment: retarg += '<hr /><h2 class="ut_label">UNDER TREATMENT</h2><hr />' return '''%s\n</div></body></html>''' % retarg except Exception as exc: LOGGER.exception("error in patientDetails.details") return "error displaying details, sorry <br />%s" % exc
def print_(self): dialog = QtGui.QPrintDialog(self.printer) if not dialog.exec_(): return self.pdfprinter.setOutputFormat(QtGui.QPrinter.PdfFormat) self.pdfprinter.setOutputFileName(localsettings.TEMP_PDF) for printer in (self.printer, self.pdfprinter): LeftMargin = 50 TopMargin = 150 serifFont = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(serifFont) serifLineHeight = fm.height() painter = QtGui.QPainter(printer) pageRect = printer.pageRect() painter.setPen(QtCore.Qt.black) painter.setFont(serifFont) center = QtGui.QTextOption(QtCore.Qt.AlignCenter) alignRight = QtGui.QTextOption(QtCore.Qt.AlignRight) if self.isDuplicate: painter.drawText( QtCore.QRectF(0, 100, pageRect.width(), serifLineHeight), QtCore.QString("DUPLICATE RECEIPT"), center) x, y = LeftMargin, TopMargin + 30 painter.drawText( x, y, "%s %s %s" % (self.title.title(), self.fname.title(), self.sname.title())) y += serifLineHeight for line in (self.addr1, self.addr2, self.addr3, self.town, self.county): if line != "": painter.drawText(x, y, str(line).title() + ",") y += serifLineHeight if self.pcde != "": painter.drawText(x, y, str(self.pcde + ".")) # postcode x, y = LeftMargin + 50, TopMargin + serifLineHeight * 10 mystr = 'Received on ' w = fm.width(mystr) painter.drawText(x, y, mystr) if not self.isDuplicate: painter.drawText( x + w, y, QtCore.QDate.currentDate().toString( localsettings.QDATE_FORMAT)) else: painter.drawText( x + w, y, self.dupdate.toString(localsettings.QDATE_FORMAT)) y += serifLineHeight * 2 painter.drawText(x, y, QtCore.QString('relating to:-')) y += serifLineHeight for key in self.receivedDict.keys(): amount = self.receivedDict[key] if float(amount) != 0: rect_f = QtCore.QRectF(x, y, 180, serifLineHeight) painter.drawText(rect_f, QtCore.QString(key)) rect_f = QtCore.QRectF(x + 180, y, 100, serifLineHeight) text = QtCore.QString(localsettings.formatMoney(amount)) painter.drawText(rect_f, text, alignRight) y += serifLineHeight y += serifLineHeight painter.drawLine(int(x), int(y), int(x) + 280, int(y)) # 130+150=280 y += serifLineHeight * 1.5 rect_f = QtCore.QRectF(x, y, 180, serifLineHeight) painter.drawText(rect_f, "TOTAL") rect_f = QtCore.QRectF(x + 180, y, 100, serifLineHeight) text = QtCore.QString(localsettings.formatMoney(self.total)) painter.drawText(rect_f, text, alignRight) y += serifLineHeight * 4 font = QtGui.QFont("Helvetica", 7) font.setItalic(True) painter.setFont(font) painter.drawText(x, y, _("Thankyou for your custom.")) return True
def details(dent, startdate, enddate, treatment_only=False, sundries_only=False): ''' retrns an html version of the cashbook table ''' db = connect() cursor = db.cursor() #note - len(headers) is used writing out the html headers = ("cbdate", "Serial NO", "Dentist", "Patient", "code", "cash", "cheque", "card", "unknown", "amt") if full_edit or (startdate.toPyDate() <= localsettings.currentDay() <= enddate.toPyDate()): headers += ("edit",) if dent == "*ALL*": cond1 = "" dentist = "All Dentists" else: dentist = localsettings.ops_reverse[str(dent)] cond1 = 'dntid="%s" and '% dentist restriction_header = "" if treatment_only: cond1 += "(code < 10 or code > 123) and " restriction_header = "TREATMENT ONLY" elif sundries_only: cond1 += "code >=14 and code <= 18 and " restriction_header = "SUNDRIES ONLY" else: restriction_header = "ALL PAYMENTS" #-- note - mysqldb doesn't play nice with DATE_FORMAT #-- hence the string is formatted entirely using python formatting query = '''select DATE_FORMAT(cbdate, '%s'), ref, dntid, descr, code, amt, cbdate, id from cashbook where %s cbdate>='%s' and cbdate<='%s' order by cbdate'''%( localsettings.OM_DATE_FORMAT, cond1, startdate.toPyDate(), enddate.toPyDate()) cursor.execute(query) rows = cursor.fetchall() retarg = "<h3>Cashbook - " retarg += "%s - %s - %s (inclusive) - %s</h3>"% (dentist, localsettings.formatDate(startdate.toPyDate()), localsettings.formatDate(enddate.toPyDate()), restriction_header) retarg += '<table width="100%" border="1"> <tr>' for header in headers: retarg += "<th>%s</th>"% header retarg += '</tr>' odd = True total, cashTOT, chequeTOT, cardTOT, otherTOT = 0, 0, 0, 0, 0 for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True #-- a row is (date,sno,dnt,patient,code,amount) retarg += '<td>%s</td><td>%s</td>'% (row[0], row[1]) retarg += '<td>%s</td>'% localsettings.ops.get(row[2]) retarg += '<td>%s</td>'% row[3] CODE = cashbookCodesDict.get(row[4]) retarg += '<td>%s</td>'% CODE amt = row[5] amt_str = localsettings.formatMoney(amt) if "CASH" in CODE: retarg += '<td align="right">%s</td>'% amt_str cashTOT += amt retarg += "<td> </td>" * 3 elif "CHEQUE" in CODE: retarg += '<td> </td><td align="right">%s</td>'% amt_str chequeTOT += amt retarg += "<td> </td>" * 2 elif "CARD" in CODE: retarg += "<td> </td>" * 2 retarg += '<td align="right">%s</td>'% amt_str cardTOT += amt retarg += "<td> </td>" else: retarg += "<td> </td>" * 3 retarg += '<td align="right">%s</td>'% amt_str otherTOT += amt retarg += '<td align="right">%s</td>'% amt_str if len(headers) == 11: if full_edit or row[6] == localsettings.currentDay(): retarg += '''<td align="center"> <a href="edit_%s">edit</a></td>'''% row[7] else: retarg += '<td align="center">n/a</a>' retarg += '</tr>\n' total += amt sum_text = "= %s + %s + %s + %s"% ( localsettings.pence_to_pounds(cashTOT), localsettings.pence_to_pounds(chequeTOT), localsettings.pence_to_pounds(cardTOT), localsettings.pence_to_pounds(otherTOT) ) retarg += '''<tr><td colspan="4">%s</td> <td><b>TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>'''% ( sum_text.replace("+ -", "- "), localsettings.formatMoney(cashTOT), localsettings.formatMoney(chequeTOT), localsettings.formatMoney(cardTOT), localsettings.formatMoney(otherTOT), localsettings.formatMoney(total)) retarg += '</table>' cursor.close() #db.close() return retarg
def print_(self): dialog = QtGui.QPrintDialog(self.printer) if not dialog.exec_(): return self.pdfprinter.setOutputFormat(QtGui.QPrinter.PdfFormat) self.pdfprinter.setOutputFileName(localsettings.TEMP_PDF) for printer in (self.printer, self.pdfprinter): LeftMargin = 50 TopMargin = 150 serifFont = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(serifFont) serifLineHeight = fm.height() painter = QtGui.QPainter(printer) pageRect = printer.pageRect() painter.setPen(QtCore.Qt.black) painter.setFont(serifFont) center = QtGui.QTextOption(QtCore.Qt.AlignCenter) alignRight = QtGui.QTextOption(QtCore.Qt.AlignRight) if self.isDuplicate: painter.drawText( QtCore.QRectF( 0, 100, pageRect.width(), serifLineHeight), QtCore.QString("DUPLICATE RECEIPT"), center) x, y = LeftMargin, TopMargin + 30 painter.drawText( x, y, "%s %s %s" % (self.title.title(), self.fname.title(), self.sname.title())) y += serifLineHeight for line in (self.addr1, self.addr2, self.addr3, self.town, self.county): if line != "": painter.drawText(x, y, str(line).title() + ",") y += serifLineHeight if self.pcde != "": painter.drawText(x, y, str(self.pcde + ".")) # postcode x, y = LeftMargin + 50, TopMargin + serifLineHeight * 10 mystr = 'Received on ' w = fm.width(mystr) painter.drawText(x, y, mystr) if not self.isDuplicate: painter.drawText(x + w, y, QtCore.QDate.currentDate().toString( localsettings.QDATE_FORMAT)) else: painter.drawText(x + w, y, self.dupdate.toString( localsettings.QDATE_FORMAT)) y += serifLineHeight * 2 painter.drawText(x, y, QtCore.QString('relating to:-')) y += serifLineHeight for key in self.receivedDict.keys(): amount = self.receivedDict[key] if float(amount) != 0: rect_f = QtCore.QRectF(x, y, 180, serifLineHeight) painter.drawText(rect_f, QtCore.QString(key)) rect_f = QtCore.QRectF(x + 180, y, 100, serifLineHeight) text = QtCore.QString(localsettings.formatMoney(amount)) painter.drawText(rect_f, text, alignRight) y += serifLineHeight y += serifLineHeight painter.drawLine( int(x), int(y), int(x) + 280, int(y)) # 130+150=280 y += serifLineHeight * 1.5 rect_f = QtCore.QRectF(x, y, 180, serifLineHeight) painter.drawText(rect_f, "TOTAL") rect_f = QtCore.QRectF(x + 180, y, 100, serifLineHeight) text = QtCore.QString(localsettings.formatMoney(self.total)) painter.drawText(rect_f, text, alignRight) y += serifLineHeight * 4 font = QtGui.QFont("Helvetica", 7) font.setItalic(True) painter.setFont(font) painter.drawText(x, y, _("Thankyou for your custom.")) return True
def details(sno): ''' returns an html page showing pt's Treatment History ''' db = connect() cursor = db.cursor() cursor.execute(QUERY, (sno, )) rows = cursor.fetchall() cursor.close() claimNo = len(rows) retarg = "<h2>Past Treatments - %d rows found</h2>" % claimNo if claimNo == 0: return retarg headers = ("Date", "Csetype", "Dentist", "Clinician", "Treatment", "Chart", "", "Fee", "PtCharge") retarg += '<table width="100%" border="1"><tr>' for header in headers: retarg += "<th>%s</th>" % header retarg += '</tr>' fee_total, ptfee_total = 0, 0 for i, (date_, cset, dnt, trt, tx, tx1, tx2, fee, ptfee, id_) in enumerate(rows): if tx1 is not None: # the "other treatment" column allows nulls, # which stuffs up the sql concat tx += tx1 retarg += ' <tr>' if i % 2 else ' <tr bgcolor="#eeeeee">' if ALLOW_TX_EDITS: extra_link = ' / <a href="om://daybook_id_edit?%s">%s</a>' % ( id_, _("Edit Tx")) else: extra_link = "" retarg += '''\n <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td align="center"> <a href="om://daybook_id?%sfeesa=%sfeesb=%s">%s</a>%s </td> <td align="right">%s</td><td align="right">%s</td>\n</tr>\n''' % ( date_, cset, localsettings.ops.get(dnt), localsettings.ops.get(trt), tx, tx2.decode("utf8").strip(" \x00"), id_, fee, ptfee, _("Ests"), extra_link, localsettings.formatMoney(fee), localsettings.formatMoney(ptfee)) fee_total += fee ptfee_total += ptfee retarg += '''<tr> <td colspan="6"></td> <td align="right"><b>TOTALS</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td>\n</tr>\n</table>''' % ( localsettings.formatMoney(fee_total), localsettings.formatMoney(ptfee_total)) return retarg
def details(sno, current_csno, include_estimates=False, include_daybook=False): ''' returns an html page showing pt's Treatment History along with estimates ''' courses = list(_get_courses(sno, current_csno)) estimates_list = estimatesHistory.getEsts(sno) if include_estimates else [] daybook_list = list(daybook.all_data(sno)) if include_daybook else [] daybook_course_guesses = {} displayed_ests = [] course_checker_errors = 0 html = "<body><html><!-- ERRORS --><!-- ORPHANS --><h2>%s - %d %s</h2>" % ( _("Past Courses of Treatment"), len(courses), _("found")) if current_csno is not None: html += "<strong>%s %s %s</strong><br />" % ( _("Ignoring course number"), current_csno, _("as this is active")) days_elapsed = None for i, course in enumerate(courses): course_html = course.to_html(ALLOW_EDIT, days_elapsed) course_ests = [] if include_estimates: est_table_init = False for est in estimates_list: if est.courseno == course.courseno: course_ests.append(est) if not est_table_init: header = est.htmlHeader() if estimatesHistory.ALLOW_EDIT: header = header.replace( "<!--editlink-->", estimatesHistory.EDIT_STRING % est.courseno) course_html += ('<table width="100%%" border="1">%s ' % header) est_table_init = True course_html += est.toHtmlRow() if est_table_init: course_html += '</table>\n' else: course_html += "%s %d" % (_("no estimate found for courseno"), course.courseno) displayed_ests += course_ests if include_daybook: daybook_html = "" if course.accd is None: accd = datetime.date(1980, 1, 1) course_html += "<em>%s</em><br />" % _( "Warning - No course acceptance date") else: accd = course.accd if course.cmpd is None: cmpd = datetime.date.today() course_html += "<em>%s</em><br />" % _( "Warning - No course completion date, " "using today to gather daybook items.") else: cmpd = course.cmpd for daybook_entry in daybook_list: if accd <= daybook_entry.date <= cmpd: try: daybook_course_guesses[course.courseno].append( daybook_entry) except KeyError: daybook_course_guesses[course.courseno] = [ daybook_entry ] gap = cmpd - daybook_entry.date if daybook.ALLOW_TX_EDITS: id_col = '<a href="daybook_id_edit?%s">%s</a>' % ( daybook_entry.id, _("Edit Tx")) else: id_col = str(daybook_entry.id) daybook_html += "<tr><td>%s</td></tr>" % ( "</td><td> ".join( (localsettings.formatDate( daybook_entry.date), daybook_entry.coursetype, localsettings.ops.get(daybook_entry.dntid), localsettings.ops.get(daybook_entry.trtid, "-"), daybook_entry.diagn, daybook_entry.perio, daybook_entry.anaes, daybook_entry.misc, daybook_entry.ndu, daybook_entry.ndl, daybook_entry.odu, daybook_entry.odl, daybook_entry.other, daybook_entry.chart.decode("utf8").strip( " %s" % chr(0)), localsettings.formatMoney(daybook_entry.feesa), localsettings.formatMoney( daybook_entry.feesb), id_col))) if daybook_html: header_rows = daybook.all_data_header() if course.cmpd is None: header_rows = header_rows.replace("<!--gap-->", _("Course is Ongoing")) elif gap.days != 0: header_rows = header_rows.replace( "<!--gap-->", "%s %s %s" % (_("Course closed"), gap.days, _("days after last treatment"))) course_html += '<table width="100%%" border=1>%s%s</table>' % ( header_rows, daybook_html) else: course_html += "%s<br />" % _( "Course dates not found in daybook") if include_estimates and include_daybook: course_check = CourseChecker( course, course_ests, daybook_course_guesses.get(course.courseno, [])) if course_check.has_errors: course_checker_errors += 1 course_html += course_check.results course_html += '''<br /> <a href="consistent_courseno?%s">%s</a>''' % ( course.courseno, _("Examine these Issues.")) days_elapsed = "" try: prev_course = courses[i + 1] if ALLOW_EDIT: merge_link = '<br /><a href="merge_courses?%s+%s">%s?</a>' % ( course.courseno, prev_course.courseno, _("Merge with previous course")) course_html = course_html.replace("<!--merge-->", merge_link) days_elapsed = (course.accd - prev_course.cmpd).days except IndexError: days_elapsed = None except TypeError: pass finally: course_html += '<br /><hr /><br />' html += course_html html += "</html></body>" orphaned_html = "" i = 0 for est in estimates_list: if est not in displayed_ests and est.courseno != current_csno: if i == 0: orphaned_html += '''<h1>%s %s</h1> <table width="100%%" border="1">%s ''' % ( _("WARNING"), _("ORPHANED ESTIMATE DATA"), est.htmlHeader().replace("#ffff99", "red")) orphaned_html += est.toHtmlRow() i += 1 if course_checker_errors: html = html.replace( "<!-- ERRORS -->", "<h3>%d %s</h3>" % (course_checker_errors, _("Errors Found"))) if i == 0: return html return html.replace( "<!-- ORPHANS -->", "%s</table><em>%s</em><br />" % (orphaned_html, _("This shouldn't happen!")))
def print_(self): dialog = QtGui.QPrintDialog(self.printer) if not dialog.exec_(): return self.pdfprinter.setOutputFormat(QtGui.QPrinter.PdfFormat) self.pdfprinter.setOutputFileName(localsettings.TEMP_PDF) for printer in (self.printer, self.pdfprinter): LeftMargin = 50 TopMargin = 150 serifFont = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(serifFont) serifLineHeight = fm.height() painter = QtGui.QPainter(printer) pageRect = printer.pageRect() painter.setPen(QtCore.Qt.black) painter.setFont(serifFont) alignRight = QtGui.QTextOption(QtCore.Qt.AlignRight) x, y = LeftMargin, TopMargin painter.drawText(x, y, "%s %s %s" % (self.title.title(), self.fname.title(), self.sname.title())) y += serifLineHeight painter.drawText(x, y, "Our Ref - " + str(self.ourref)) y += serifLineHeight * 1.5 mystr = 'Estimate Printed on ' w = fm.width(mystr) painter.drawText(x, y, mystr) painter.drawText(x + w, y, QtCore.QDate.currentDate().toString( localsettings.QDATE_FORMAT)) x = LeftMargin + 10 y += serifLineHeight pt_total = 0 # separate into NHS and non-NHS items. sorted_ests = {"N": [], "P": []} for est in self.estItems: if "N" in est.csetype: sorted_ests["N"].append(est) else: sorted_ests["P"].append(est) for type_, description in ( ("N", _("NHS items")), ("P", _("Private items")) ): if sorted_ests[type_]: y += serifLineHeight painter.drawText( QtCore.QRectF(x, y, 400, serifLineHeight), description) y += serifLineHeight for est in sorted_ests[type_]: pt_total += est.ptfee number = est.number item = est.description amount = est.ptfee # print number,item,amount mult = "" if number > 1: mult = "s" item = item.replace("*", mult) item = item.replace("^", "") painter.drawText(QtCore.QRectF(x, y, 60, serifLineHeight), str(number)) painter.drawText( QtCore.QRectF(x + 60, y, 280, serifLineHeight), item) painter.drawText( QtCore.QRectF(x + 280, y, 100, serifLineHeight), localsettings.formatMoney(amount), alignRight) y += serifLineHeight y += serifLineHeight # 280+100=280 painter.drawLine(int(x), int(y), int(x) + 380, int(y)) y += serifLineHeight * 1.5 painter.drawText(QtCore.QRectF(x, y, 180, serifLineHeight), _("TOTAL")) painter.drawText(QtCore.QRectF(x + 280, y, 100, serifLineHeight), localsettings.formatMoney(pt_total), alignRight) y += serifLineHeight * 4 font = QtGui.QFont("Helvetica", 7) font.setItalic(True) painter.setFont(font) option = QtGui.QTextOption(QtCore.Qt.AlignCenter) option.setWrapMode(QtGui.QTextOption.WordWrap) painter.drawText( QtCore.QRectF(0, y, pageRect.width(), 31), _("Please note, this estimate may be subject to change if " "clinical circumstances dictate."), option) return True
def print_(self): dialog = QtPrintSupport.QPrintDialog(self.printer, self.parent) if not dialog.exec_(): return self.pdfprinter.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat) self.pdfprinter.setOutputFileName(localsettings.TEMP_PDF) for printer in (self.printer, self.pdfprinter): LeftMargin = 50 TopMargin = 150 serifFont = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(serifFont) serifLineHeight = fm.height() painter = QtGui.QPainter(printer) pageRect = printer.pageRect() painter.setPen(QtCore.Qt.black) painter.setFont(serifFont) alignRight = QtGui.QTextOption(QtCore.Qt.AlignRight) x, y = LeftMargin, TopMargin painter.drawText( x, y, "%s %s %s" % (self.title.title(), self.fname.title(), self.sname.title())) y += serifLineHeight painter.drawText(x, y, "Our Ref - " + str(self.ourref)) y += serifLineHeight * 1.5 mystr = 'Estimate Printed on ' w = fm.width(mystr) painter.drawText(x, y, mystr) painter.drawText( x + w, y, QtCore.QDate.currentDate().toString( localsettings.QDATE_FORMAT)) x = LeftMargin + 10 y += serifLineHeight pt_total = 0 # separate into NHS and non-NHS items. sorted_ests = {"N": [], "P": []} for est in self.estItems: if "N" in est.csetype: sorted_ests["N"].append(est) else: sorted_ests["P"].append(est) for type_, description in (("N", _("NHS items")), ("P", _("Private items"))): if sorted_ests[type_]: y += serifLineHeight painter.drawText(QtCore.QRectF(x, y, 400, serifLineHeight), description) y += serifLineHeight for est in sorted_ests[type_]: pt_total += est.ptfee number = est.number item = est.description amount = est.ptfee # print number,item,amount mult = "" if number > 1: mult = "s" item = item.replace("*", mult) item = item.replace("^", "") painter.drawText(QtCore.QRectF(x, y, 60, serifLineHeight), str(number)) painter.drawText( QtCore.QRectF(x + 60, y, 280, serifLineHeight), item) painter.drawText( QtCore.QRectF(x + 280, y, 100, serifLineHeight), localsettings.formatMoney(amount), alignRight) y += serifLineHeight y += serifLineHeight # 280+100=280 painter.drawLine(int(x), int(y), int(x) + 380, int(y)) y += serifLineHeight * 1.5 painter.drawText(QtCore.QRectF(x, y, 180, serifLineHeight), _("TOTAL")) painter.drawText(QtCore.QRectF(x + 280, y, 100, serifLineHeight), localsettings.formatMoney(pt_total), alignRight) y += serifLineHeight * 4 font = QtGui.QFont("Helvetica", 7) font.setItalic(True) painter.setFont(font) option = QtGui.QTextOption(QtCore.Qt.AlignCenter) option.setWrapMode(QtGui.QTextOption.WordWrap) painter.drawText( QtCore.QRectF(0, y, pageRect.width(), 31), _("Please note, this estimate may be subject to change if " "clinical circumstances dictate."), option) return True
def details(sno): ''' returns an html page showing pt's payment History ''' values = (localsettings.OM_DATE_FORMAT, "%06d" % sno) db = connect() cursor = db.cursor() cursor.execute(QUERY, values) rows = cursor.fetchall() cursor.close() claimNo = len(rows) if claimNo == 0: return "<h2>No Payments Found</h2>" retarg = '<html><body><table width="100%" border="1">' retarg += '<tr>' for header in HEADERS: retarg += "<th>%s</th>" % header retarg += '</tr>' odd = True total, cashTOT, chequeTOT, cardTOT, otherTOT = 0, 0, 0, 0, 0 for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True #-- a row is (date,sno,dnt,patient,code,amount) retarg += '<td>%s</td>' % (row[0]) retarg += '<td>%s</td>' % localsettings.ops.get(row[1]) retarg += '<td>%s</td>' % row[2] CODE = localsettings.cashbookCodesDict.get(row[3], "UNKNOWN") retarg += '<td>%s</td>' % CODE amt = row[4] amt_str = localsettings.formatMoney(amt) if "CASH" in CODE: retarg += '<td align="right">%s</td>' % amt_str cashTOT += amt retarg += "<td> </td>" * 3 elif "CHEQUE" in CODE: retarg += '<td> </td><td align="right">%s</td>' % amt_str chequeTOT += amt retarg += "<td> </td>" * 2 elif "CARD" in CODE: retarg += "<td> </td>" * 2 retarg += '<td align="right">%s</td>' % amt_str cardTOT += amt retarg += "<td> </td>" else: retarg += "<td> </td>" * 3 retarg += '<td align="right">%s</td>' % amt_str otherTOT += amt retarg += '<td align="right">%s</td>' % amt_str retarg += '</tr>\n' total += amt retarg += '''<tr><td colspan="3"></td> <td><b>TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.formatMoney(cashTOT), localsettings.formatMoney(chequeTOT), localsettings.formatMoney(cardTOT), localsettings.formatMoney(otherTOT), localsettings.formatMoney(total)) retarg += '</table></body></html>' return retarg
def html(serialno, courseno): values = (serialno, courseno) db = connect() cursor = db.cursor() cursor.execute(QUERY, values) rows = cursor.fetchall() cursor.close() est_count = len(rows) if est_count == 0: return "<h2>No Estimate Found</h2>" completed, planned = [], [] for description, fee, comp in rows: if comp: completed.append( (description, fee, localsettings.formatMoney(fee))) else: planned.append((description, fee, localsettings.formatMoney(fee))) n_rows = len(planned) if len(completed) > n_rows: n_rows = len(completed) html_ = ''' <table> <tr> <th colspan="2">Planned</th> <th> </th> <th colspan="2">Completed</th> </tr> ''' c_tot, p_tot = 0, 0 for i in range(n_rows): try: c_desc, fee, c_fee = completed[i] c_tot += fee except IndexError: c_desc, c_fee = "", "" try: p_desc, fee, p_fee = planned[i] p_tot += fee except IndexError: p_desc, p_fee = "", "" html_ += '''<tr> <td width= '30%%'>%s</td> <td width= '20%%' align='right'>%s</td> <td /> <td width= '30%%'>%s</td> <td width= '20%%' align='right'>%s</td> </tr>''' % (p_desc, p_fee, c_desc, c_fee) html_ += '''<tr> <td colspan="2" align='right'><b>%s</b></td> <td /> <td colspan="2" align='right'><b>%s</b></td> </tr>''' % (localsettings.formatMoney(p_tot), localsettings.formatMoney(c_tot)) return html_ + "</table><br />"
def details(sno): ''' returns an html page showing pt's Treatment History ''' db = connect() cursor = db.cursor() cursor.execute(QUERY, (sno,)) rows = cursor.fetchall() cursor.close() claimNo = len(rows) retarg = "<h2>Past Treatments - %d rows found</h2>" % claimNo if claimNo == 0: return retarg headers = ("Date", "Csetype", "Dentist", "Clinician", "Treatment", "Chart", "", "Fee", "PtCharge") retarg += '<table width="100%" border="1"><tr>' for header in headers: retarg += "<th>%s</th>" % header retarg += '</tr>' fee_total, ptfee_total = 0, 0 for i, (date_, cset, dnt, trt, tx, tx1, tx2, fee, ptfee, id_) in enumerate(rows): if tx1 is not None: # the "other treatment" column allows nulls, # which stuffs up the sql concat tx += tx1 retarg += ' <tr>' if i % 2 else ' <tr bgcolor="#eeeeee">' if ALLOW_TX_EDITS: extra_link = ' / <a href="om://daybook_id_edit?%s">%s</a>' % ( id_, _("Edit Tx")) else: extra_link = "" retarg += '''\n <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td align="center"> <a href="om://daybook_id?%sfeesa=%sfeesb=%s">%s</a>%s </td> <td align="right">%s</td><td align="right">%s</td>\n</tr>\n''' % ( date_, cset, localsettings.ops.get(dnt), localsettings.ops.get(trt), tx, tx2.decode("utf8").strip(" \x00"), id_, fee, ptfee, _("Ests"), extra_link, localsettings.formatMoney(fee), localsettings.formatMoney(ptfee) ) fee_total += fee ptfee_total += ptfee retarg += '''<tr> <td colspan="6"></td> <td align="right"><b>TOTALS</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td>\n</tr>\n</table>''' % ( localsettings.formatMoney(fee_total), localsettings.formatMoney(ptfee_total)) return retarg
def details(sno): ''' returns an html page showing pt's Treatment History ''' db = connect() cursor = db.cursor() query = '''select DATE_FORMAT(date,'%s'), coursetype, dntid, trtid, concat(diagn,perio,anaes,misc,ndu,ndl,odu,odl), other,chart,feesa,feesb from daybook where serialno = %s order by date desc, id desc''' % ( localsettings.OM_DATE_FORMAT, sno) # can't use the preffered query, values # here as the dateformat of %d/%m/%Y stuffs it up! cursor.execute(query) rows = cursor.fetchall() cursor.close() claimNo = len(rows) retarg = "<h2>Past Treatments - %d rows found</h2>" % claimNo if claimNo == 0: return retarg headers = ("Date", "Csetype", "Dentist", "Clinician", "Treatment", "Chart", "Fee", "PtCharge") retarg += '<table width="100%" border="1"><tr>' for header in headers: retarg += "<th>%s</th>" % header retarg += '</tr>' odd = True fee_total, ptfee_total = 0, 0 for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True retarg += '<td>%s</td><td>%s</td>' % (row[0], row[1]) retarg += '<td>%s</td><td>%s</td>' % (localsettings.ops.get( row[2]), localsettings.ops.get(row[3])) treatment = row[4] if row[5] is not None: #-- the "other" column allows nulls, which stuffs up the sql concat treatment += row[5] retarg += '<td>%s</td>' % treatment treatment = row[6] retarg += '<td>%s</td>' % treatment.strip("\x00") fee = row[7] retarg += '<td align="right">%s</td>' % ( localsettings.formatMoney(fee)) ptfee = row[8] retarg += '<td align="right">%s</td>' % ( localsettings.formatMoney(ptfee)) fee_total += fee ptfee_total += ptfee retarg += '</tr>\n' retarg += '''<tr><td colspan="5"></td> <td><b>TOTALS</b></td><td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % (localsettings.formatMoney( fee_total), localsettings.formatMoney(ptfee_total)) retarg += '</table>' return retarg
def details(pt, Saved=True): '''returns an html set showing pt name etc...''' try: retarg = header(pt) + '<hr />' if "N" in pt.cset: retarg += '''<img src="%s/nhs_scot.png" alt="NHS" /> <br />'''% localsettings.resources_path if pt.exemption != "": retarg += " exemption=%s"% str(pt.exemption) else: retarg += "NOT EXEMPT" retarg += "<br />" elif "I" in pt.cset: retarg += '''<img src="%s/hdp_small.png" alt="HDP" /> <br />'''% localsettings.resources_path elif "P" in pt.cset: retarg += '''<img src="%s/private.png" alt="PRIVATE" /> <br />'''% localsettings.resources_path else: retarg += 'UNKNOWN COURSETYPE = %s <br />'% str(pt.cset) #-- removed this next code as feescale is always the same #if pt.pf11!=0: # retarg += '(feescale %s)<br />'%chr(pt.pf11) retarg += "%s<br />"% pt.fee_table.briefName try: retarg += 'dentist = %s'% localsettings.ops[pt.dnt1] if pt.dnt2 != 0 and pt.dnt1 != pt.dnt2: retarg += '/%s'% localsettings.ops[pt.dnt2] except KeyError, e: retarg += '<h4>Please Set a Dentist for this patient!</h4><hr />' if pt.memo != '': retarg += '<h4>Memo</h4>%s<hr />'% pt.memo retarg += '''<table border="1">' <tr><td>Last IO Xrays</td><td>%s</td></tr> <tr><td>Last OPG</td><td>%s</td></tr> <tr><td>Last Sp</td><td>%s</td></tr> '''% (localsettings.formatDate(pt.pd9), localsettings.formatDate(pt.pd8), localsettings.formatDate(pt.pd10)) letype = "" lastexam = datetime.date(1,1,1) i = 0 for date in (pt.pd5, pt.pd6, pt.pd7): if date and date > lastexam: lastexam = date letype = ("(CE)", "(ECE)", "(FCA)")[i] i += 1 if lastexam == datetime.date(1,1,1): lastexam = None if letype != "": retarg += '<tr><td>Last Exam %s</td><td>%s</td></tr>'% ( letype, localsettings.formatDate(lastexam)) if pt.recall_active: retarg += '''<tr><td>Recall Date</td><td>%s</td></tr> </table>''' % localsettings.formatDate(pt.recd) else: retarg += '<tr><td colspan="2">%s</td></tr></table>'% _( "DO NOT RECALL") if not Saved: alert = "<br />NOT SAVED" else: alert = "" if pt.fees > 0: amount = localsettings.formatMoney(pt.fees) retarg += '<hr /><h3 class="debt">Account = %s %s</h3>'% ( amount, alert) if pt.fees < 0: amount = localsettings.formatMoney(-pt.fees) retarg += '<hr /><h3>%s in credit %s</h3>'% (amount, alert) if pt.underTreatment: retarg += '<hr /><h2 class="ut_label">UNDER TREATMENT</h2><hr />' return '''%s\n</div></body></html>'''% retarg
def details(pt): ''' returns an html set showing pt name etc... ''' try: html = header(pt) + '<hr />' if "N" in pt.cset: html += '''<img src="%s/nhs_scot.png" alt="NHS" /> <br />''' % localsettings.resources_path if pt.exemption != "": html += "%s=%s" % (_("exemption"), pt.exemption) else: html += _("NOT EXEMPT") html += "<br />" elif "I" in pt.cset: html += '''<img src="%s/hdp_small.png" alt="HDP" /> <br />''' % localsettings.resources_path elif "P" in pt.cset: html += '''<img src="%s/private.png" alt="PRIVATE" /> <br />''' % localsettings.resources_path else: html += '%s = %s <br />' % (_("UNKNOWN COURSETYPE"), pt.cset) html += "%s<br />" % pt.fee_table.briefName try: html += 'dentist = %s' % localsettings.ops[pt.dnt1] if pt.dnt2 != 0 and pt.dnt1 != pt.dnt2: html += '/%s' % localsettings.ops[pt.dnt2] except KeyError: html += '<h4>%s</h4><hr />' % _( "Please Set a Dentist for this patient!") if pt.underTreatment: html += '<hr /><h2 class="ut_label">%s</h2><hr />' % _( "UNDER TREATMENT") if pt.memo != '': html += '<h4>%s</h4>%s<hr />' % (_("Memo"), pt.memo) tx_dates = [ (_("Med Form"), pt.mh_form_date), (_("Med Notes"), pt.mh_chkdate), (_("Treatment"), pt.last_treatment_date), (_("IO xrays"), pt.pd9), (_("Panoral"), pt.pd8), (_("Scaling"), pt.pd10) ] letype, le_date = "", datetime.date(1, 1, 1) for i, date_ in enumerate((pt.pd5, pt.pd6, pt.pd7)): if date_ and date_ > le_date: le_date = date_ letype = ("(CE)", "(ECE)", "(FCA)")[i] if le_date == datetime.date(1, 1, 1): le_date = None if letype != "": tx_dates.append(('%s %s' % (_("Exam"), letype), le_date)) html += '<h4>%s</h4><table width="100%%" border="1">' % _("History") for i, (att, val) in enumerate(tx_dates): markup = ("", "") if i in (2, 6): markup = ("<b>", "</b") elif i == 0: if pt.mh_form_date is None: markup = ('<b style="color:red;">!!', "</b>") elif i == 1: try: if pt.mh_chkdate < pt.mh_form_date: markup = ('<b style="color:red;">', "</b>") except TypeError: pass html += ''' <tr> <td align="center">%s</td> <td align="center">%s%s%s</td> </tr>''' % (att, markup[0], localsettings.formatDate(val), markup[1]) html += "</table>" html += "<h4>%s</h4>" % _("Recall") if pt.recall_active: month_start = datetime.date(localsettings.currentDay().year, localsettings.currentDay().month, 1) if pt.recd > month_start or pt.has_exam_booked: html += "%s " % localsettings.formatDate(pt.recd) html += _("(Exam Booked)") if pt.has_exam_booked else "" else: html += '<div style="color:red;">%s<br />%s</div>' % ( localsettings.formatDate(pt.recd), _("Exam Due")) else: html += '<div style="color:red;">%s</div>' % _("DO NOT RECALL") if pt.fees > 0: amount = localsettings.formatMoney(pt.fees) html += '<hr /><h3 class="debt">%s = %s</h3>' % (_("Account"), amount) if pt.fees < 0: amount = localsettings.formatMoney(-pt.fees) html += '<hr /><h3>%s %s</h3>' % (amount, _("in credit")) if pt.has_changes: html += '<hr /><h3 class="debt">%s</h3>' % ( _("RECORD HAS UNSAVED CHANGES")) return '''%s\n</div></body></html>''' % html except Exception as exc: LOGGER.exception("error in patientDetails.details") return "error displaying details, sorry <br />%s" % exc
def details(regdent, trtdent, startdate, enddate): ''' returns an html table, for regdent, trtdent,startdate,enddate ''' cond1, cond2 = "", "" try: if regdent != "*ALL*": cond1 = 'dntid=%s and' % localsettings.ops_reverse[regdent] if trtdent != "*ALL*": cond2 = 'trtid=%s and' % localsettings.ops_reverse[trtdent] except KeyError: print "Key Error - %s or %s unregconised" % (regdent, trtdent) return '<html><body>%s</body></html>' % _( "Error - unrecognised practioner- sorry") total, nettotal = 0, 0 iterDate = QDate(startdate.year(), startdate.month(), 1) db = connect() cursor = db.cursor() retarg = '''<html><body> <h3>Patients of %s treated by %s between %s and %s (inclusive)</h3>''' % ( regdent, trtdent, localsettings.formatDate(startdate.toPyDate()), localsettings.formatDate(enddate.toPyDate())) retarg += '''<table width="100%" border="1"><tr><th>DATE</th> <th>Dents</th><th>Serial Number</th><th>Name</th> <th>Pt Type</th><th>Treatment</th><th>Gross Fee</th><th>Net Fee</th>''' while enddate >= iterDate: monthtotal, monthnettotal = 0, 0 if startdate > iterDate: queryStartDate = startdate else: queryStartDate = iterDate queryEndDate = iterDate.addMonths(1).addDays(-1) if enddate < queryEndDate: queryEndDate = enddate #-- note - mysqldb doesn't play nice with DATE_FORMAT #-- hence the string is formatted entirely using python formatting query = '''select DATE_FORMAT(date,'%s'), serialno, coursetype, dntid, trtid, diagn, perio, anaes, misc, ndu, ndl, odu, odl, other, chart, feesa, feesb, feesc, id from daybook where %s %s date >= '%s' and date <= '%s' order by date''' % ( localsettings.OM_DATE_FORMAT, cond1, cond2, queryStartDate.toPyDate(), queryEndDate.toPyDate()) cursor.execute(query) rows = cursor.fetchall() odd = True for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True retarg += "<td>'%s' %s</td>" % (row[18], row[0]) try: retarg += '<td> %s / ' % localsettings.ops[row[3]] except KeyError: retarg += "<td>?? / " try: retarg += localsettings.ops[row[4]] except KeyError: retarg += "??" retarg += '</td><td>%s</td>' % row[1] cursor.execute( 'select fname,sname from patients where serialno=%s' % row[1]) names = cursor.fetchall() if names != (): name = names[0] retarg += '<td>%s %s</td>' % (name[0].title(), name[1].title()) else: retarg += "<td>NOT FOUND</td>" retarg += '<td>%s</td>' % row[2] tx = "" for item in (5, 6, 7, 8, 9, 10, 11, 12, 13, 14): if row[item] is not None and row[item] != "": tx += "%s " % row[item] retarg += '''<td>%s</td><td align="right">%s</td> <td align="right">%s</td></tr>''' % (tx.strip("%s " % chr(0)), localsettings.formatMoney( row[15]), localsettings.formatMoney(row[16])) total += int(row[15]) monthtotal += int(row[15]) nettotal += int(row[16]) monthnettotal += int(row[16]) retarg += '''<tr><td colspan="5"></td><td><b>%s TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.monthName(iterDate.toPyDate()), localsettings.formatMoney(monthtotal), localsettings.formatMoney(monthnettotal)) iterDate = iterDate.addMonths(1) cursor.close() # db.close() retarg += '''<tr><td colspan="5"></td><td><b>GRAND TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr></table></body></html>''' % ( localsettings.formatMoney(total), localsettings.formatMoney(nettotal)) return retarg
def details(pt): ''' returns an html set showing pt name etc... ''' try: html = header(pt) + '<hr />' if "N" in pt.cset: html += '''<img src="%s/nhs_scot.png" alt="NHS" /> <br />''' % localsettings.resources_path if pt.exemption != "": html += "%s=%s" % (_("exemption"), pt.exemption) else: html += _("NOT EXEMPT") html += "<br />" elif "I" in pt.cset: html += '''<img src="%s/hdp_small.png" alt="HDP" /> <br />''' % localsettings.resources_path elif "P" in pt.cset: html += '''<img src="%s/private.png" alt="PRIVATE" /> <br />''' % localsettings.resources_path else: html += '%s = %s <br />' % (_("UNKNOWN COURSETYPE"), pt.cset) html += "%s<br />" % pt.fee_table.briefName try: html += 'dentist = %s' % localsettings.ops[pt.dnt1] if pt.dnt2 != 0 and pt.dnt1 != pt.dnt2: html += '/%s' % localsettings.ops[pt.dnt2] except KeyError: html += '<h4>%s</h4><hr />' % _( "Please Set a Dentist for this patient!") if pt.underTreatment: html += '<hr /><h2 class="ut_label">%s</h2><hr />' % _( "UNDER TREATMENT") if pt.memo != '': html += '<h4>%s</h4>%s<hr />' % (_("Memo"), pt.memo) tx_dates = [(_("Med Form"), pt.mh_form_date), (_("Med Notes"), pt.mh_chkdate), (_("Treatment"), pt.last_treatment_date), (_("IO xrays"), pt.pd9), (_("Panoral"), pt.pd8), (_("Scaling"), pt.pd10)] letype, le_date = "", datetime.date(1, 1, 1) for i, date_ in enumerate((pt.pd5, pt.pd6, pt.pd7)): if date_ and date_ > le_date: le_date = date_ letype = ("(CE)", "(ECE)", "(FCA)")[i] if le_date == datetime.date(1, 1, 1): le_date = None if letype != "": tx_dates.append(('%s %s' % (_("Exam"), letype), le_date)) html += '<h4>%s</h4><table width="100%%" border="1">' % _("History") for i, (att, val) in enumerate(tx_dates): markup = ("", "") if i in (2, 6): markup = ("<b>", "</b") elif i == 0: if pt.mh_form_date is None: markup = ('<b style="color:red;">!!', "</b>") elif i == 1: try: if pt.mh_chkdate < pt.mh_form_date: markup = ('<b style="color:red;">', "</b>") except TypeError: pass html += ''' <tr> <td align="center">%s</td> <td align="center">%s%s%s</td> </tr>''' % (att, markup[0], localsettings.formatDate(val), markup[1]) html += "</table>" html += "<h4>%s</h4>" % _("Recall") if pt.recall_active: month_start = datetime.date(localsettings.currentDay().year, localsettings.currentDay().month, 1) if pt.recd > month_start or pt.has_exam_booked: html += "%s " % localsettings.formatDate(pt.recd) html += _("(Exam Booked)") if pt.has_exam_booked else "" else: html += '<div style="color:red;">%s<br />%s</div>' % ( localsettings.formatDate(pt.recd), _("Exam Due")) else: html += '<div style="color:red;">%s</div>' % _("DO NOT RECALL") if pt.fees > 0: amount = localsettings.formatMoney(pt.fees) html += '<hr /><h3 class="debt">%s = %s</h3>' % (_("Account"), amount) if pt.fees < 0: amount = localsettings.formatMoney(-pt.fees) html += '<hr /><h3>%s %s</h3>' % (amount, _("in credit")) if pt.has_changes: html += '<hr /><h3 class="debt">%s</h3>' % ( _("RECORD HAS UNSAVED CHANGES")) return '''%s\n</div></body></html>''' % html except Exception as exc: LOGGER.exception("error in patientDetails.details") return "error displaying details, sorry <br />%s" % exc
def details(sno): ''' returns an html page showing pt's Treatment History ''' db = connect() cursor = db.cursor() query = '''select DATE_FORMAT(date,'%s'), coursetype, dntid, trtid, concat(diagn,perio,anaes,misc,ndu,ndl,odu,odl), other,chart,feesa,feesb from daybook where serialno = %s order by date desc, id desc''' % ( localsettings.OM_DATE_FORMAT, sno) # can't use the preffered query, values # here as the dateformat of %d/%m/%Y stuffs it up! cursor.execute(query) rows = cursor.fetchall() cursor.close() claimNo = len(rows) retarg = "<h2>Past Treatments - %d rows found</h2>" % claimNo if claimNo == 0: return retarg headers = ("Date", "Csetype", "Dentist", "Clinician", "Treatment", "Chart", "Fee", "PtCharge") retarg += '<table width="100%" border="1"><tr>' for header in headers: retarg += "<th>%s</th>" % header retarg += '</tr>' odd = True fee_total, ptfee_total = 0, 0 for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True retarg += '<td>%s</td><td>%s</td>' % (row[0], row[1]) retarg += '<td>%s</td><td>%s</td>' % ( localsettings.ops.get(row[2]), localsettings.ops.get(row[3])) treatment = row[4] if row[5] is not None: #-- the "other" column allows nulls, which stuffs up the sql concat treatment += row[5] retarg += '<td>%s</td>' % treatment treatment = row[6] retarg += '<td>%s</td>' % treatment.strip("\x00") fee = row[7] retarg += '<td align="right">%s</td>' % ( localsettings.formatMoney(fee)) ptfee = row[8] retarg += '<td align="right">%s</td>' % ( localsettings.formatMoney(ptfee)) fee_total += fee ptfee_total += ptfee retarg += '</tr>\n' retarg += '''<tr><td colspan="5"></td> <td><b>TOTALS</b></td><td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( localsettings.formatMoney(fee_total), localsettings.formatMoney(ptfee_total)) retarg += '</table>' return retarg
def details(dent, startdate, enddate, treatment_only=False, sundries_only=False): ''' retrns an html version of the cashbook table ''' db = connect() cursor = db.cursor() # note - len(headers) is used writing out the html headers = ("cbdate", "Serial NO", "Dentist", "Patient", "code", "cash", "cheque", "card", "unknown", "amt") if full_edit or (startdate.toPyDate() <= localsettings.currentDay() <= enddate.toPyDate()): headers += ("edit", ) if dent == "*ALL*": cond1 = "" dentist = "All Dentists" else: dentist = localsettings.ops_reverse[str(dent)] cond1 = 'dntid="%s" and ' % dentist restriction_header = "" if treatment_only: cond1 += "(code < 10 or code > 123) and " restriction_header = "TREATMENT ONLY" elif sundries_only: cond1 += "code >=14 and code <= 18 and " restriction_header = "SUNDRIES ONLY" else: restriction_header = "ALL PAYMENTS" #-- note - mysqldb doesn't play nice with DATE_FORMAT #-- hence the string is formatted entirely using python formatting query = '''select DATE_FORMAT(cbdate, '%s'), ref, dntid, descr, code, amt, cbdate, id from cashbook where %s cbdate>='%s' and cbdate<='%s' order by cbdate''' % (localsettings.OM_DATE_FORMAT, cond1, startdate.toPyDate(), enddate.toPyDate()) cursor.execute(query) rows = cursor.fetchall() retarg = "<h3>Cashbook - " retarg += "%s - %s - %s (inclusive) - %s</h3>" % ( dentist, localsettings.formatDate(startdate.toPyDate()), localsettings.formatDate(enddate.toPyDate()), restriction_header) retarg += '<table width="100%" border="1"> <tr>' for header in headers: retarg += "<th>%s</th>" % header retarg += '</tr>' odd = True total, cashTOT, chequeTOT, cardTOT, otherTOT = 0, 0, 0, 0, 0 for row in rows: if odd: retarg += '<tr bgcolor="#eeeeee">' odd = False else: retarg += '<tr>' odd = True #-- a row is (date,sno,dnt,patient,code,amount) retarg += '<td>%s</td><td>%s</td>' % (row[0], row[1]) retarg += '<td>%s</td>' % localsettings.ops.get(row[2]) retarg += '<td>%s</td>' % row[3] CODE = localsettings.cashbookCodesDict.get(row[4]) retarg += '<td>%s</td>' % CODE amt = row[5] amt_str = localsettings.formatMoney(amt) if "CASH" in CODE: retarg += '<td align="right">%s</td>' % amt_str cashTOT += amt retarg += "<td> </td>" * 3 elif "CHEQUE" in CODE: retarg += '<td> </td><td align="right">%s</td>' % amt_str chequeTOT += amt retarg += "<td> </td>" * 2 elif "CARD" in CODE: retarg += "<td> </td>" * 2 retarg += '<td align="right">%s</td>' % amt_str cardTOT += amt retarg += "<td> </td>" else: retarg += "<td> </td>" * 3 retarg += '<td align="right">%s</td>' % amt_str otherTOT += amt retarg += '<td align="right">%s</td>' % amt_str if len(headers) == 11: if full_edit or row[6] == localsettings.currentDay(): retarg += '''<td align="center"> <a href="edit_%s">edit</a></td>''' % row[7] else: retarg += '<td align="center">n/a</a>' retarg += '</tr>\n' total += amt sum_text = "= %s + %s + %s + %s" % ( localsettings.pence_to_pounds(cashTOT), localsettings.pence_to_pounds(chequeTOT), localsettings.pence_to_pounds(cardTOT), localsettings.pence_to_pounds(otherTOT)) retarg += '''<tr><td colspan="4">%s</td> <td><b>TOTAL</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td> <td align="right"><b>%s</b></td></tr>''' % ( sum_text.replace("+ -", "- "), localsettings.formatMoney(cashTOT), localsettings.formatMoney(chequeTOT), localsettings.formatMoney(cardTOT), localsettings.formatMoney(otherTOT), localsettings.formatMoney(total)) retarg += '</table>' cursor.close() # db.close() return retarg