def getEsts(sno, courseno=None): db = connect() cursor = db.cursor() if courseno is None: cursor.execute(QUERY, (sno, )) else: cursor.execute(COURSE_QUERY, (sno, courseno)) rows = cursor.fetchall() cursor.close() estimates = OrderedDict() for row in rows: hash_ = row[10] completed = bool(row[9]) tx_hash = TXHash(hash_, completed) ix = row[0] est = estimates.get(ix, Estimate()) est.ix = ix est.courseno = row[11] est.number = row[1] est.itemcode = row[2] est.description = row[3] est.fee = row[4] est.ptfee = row[5] est.feescale = row[6] est.csetype = row[7] est.dent = row[8] try: est.tx_hashes.append(tx_hash) except AttributeError: est.tx_hashes = [tx_hash] estimates[ix] = est return list(estimates.values())
def add_treatment_to_estimate(om_gui, att, shortcut, dentid, tx_hashes, itemcode=None, csetype=None, descr=None, fee=None, ptfee=None, chosen_feescale=None): ''' add an item to the patient's estimate usercode unnecessary if itemcode is provided. ''' def _tooth_code_search(att, shortcut): itemcode = table.getToothCode(att, shortcut) if itemcode != "-----": return itemcode, table LOGGER.debug("%s %s not matched by %s" % (att, shortcut, table)) for alt_table in localsettings.FEETABLES.tables.itervalues(): if alt_table == table or not alt_table.is_current: continue alt_code = alt_table.getToothCode(att, shortcut) if alt_code != "-----": if QtGui.QMessageBox.question( om_gui, _("Confirm"), u"<p><b>%s %s</b> %s.</p><p>%s <em>%s</em></p><hr />%s" % ( att, shortcut, _( "was not found in the patient's default feescale"), _( "It is matched in another feescale -"), alt_table.briefName, _("Shall we add this item from this feescale?")), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: return alt_code, alt_table return itemcode, table def _user_code_search(usercode): itemcode = table.getItemCodeFromUserCode(usercode) if itemcode != "-----": return itemcode, table LOGGER.debug("%s not matched by %s" % (usercode, table)) for alt_table in localsettings.FEETABLES.tables.itervalues(): if alt_table == table or not alt_table.is_current: continue alt_code = alt_table.getItemCodeFromUserCode(usercode) if alt_code != "-----": if QtGui.QMessageBox.question( om_gui, _("Confirm"), u"<p><b>%s</b> %s.</p><p>%s <em>%s</em></p><hr />%s" % ( usercode, _( "was not found in the patient's default feescale"), _( "It is matched in another feescale -"), alt_table.briefName, _("Shall we add this item from this feescale?")), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: return alt_code, alt_table return itemcode, table usercode = ("%s %s" % (att, shortcut)) LOGGER.debug("%s %s %s %s %s %s %s %s %s" % ( usercode, dentid, tx_hashes, itemcode, csetype, descr, fee, ptfee, chosen_feescale) ) for tx_hash in tx_hashes: assert isinstance(tx_hash, TXHash), "bad form Neil" pt = om_gui.pt est = Estimate() est.ix = None # -- this will be generated by autoincrement on commit est.serialno = pt.serialno est.courseno = pt.courseno0 if chosen_feescale is None: table = pt.fee_table else: table = chosen_feescale if re.match("[ul][lr][1-8A-E]", att): if itemcode is None: itemcode, table = _tooth_code_search(att, shortcut) if descr is None: tooth_name = att.upper() descr = table.getItemDescription(itemcode, usercode) descr = descr.replace("*", " %s" % tooth_name) else: if itemcode is None: itemcode, table = _user_code_search(usercode) if descr is None: descr = table.getItemDescription(itemcode, usercode) est.itemcode = itemcode est.description = descr est.csetype = table.categories[0] if fee is None and ptfee is None: # look up the fee here est.fee, est.ptfee = table.getFees(itemcode, pt, est.csetype, shortcut) else: est.fee, est.ptfee = fee, ptfee est.tx_hashes = tx_hashes est.dent = dentid pt.estimates.append(est) if itemcode == "-----": om_gui.advise(u"%s - %s <b>%s</b><br />%s.<hr />%s" % ( _("WARNING"), _("treatment"), usercode, _("has not been succesfully priced"), _("Please edit the estimate manually")), 1) return True
def getEsts(sno): db = connect() cursor = db.cursor() cursor.execute(QUERY, (sno,)) rows = cursor.fetchall() cursor.close() estimates = [] for row in rows: hash_ = row[10] completed = bool(row[9]) tx_hash = TXHash(hash_, completed) ix = row[0] found = False #use existing est if one relates to multiple treatments for existing_est in estimates: if existing_est.ix == ix: existing_est.tx_hashes.append(tx_hash) found = True break if found: continue #initiate a custom data class est = Estimate() est.ix = ix est.courseno = row[11] est.number = row[1] est.itemcode = row[2] est.description = row[3] est.fee = row[4] est.ptfee = row[5] est.feescale = row[6] est.csetype = row[7] est.dent = row[8] #est.category = "TODO" #est.type_ = "TODO" est.tx_hashes = [tx_hash] estimates.append(est) cursor.close() return estimates
def get_ests(serialno, courseno): ''' get estimate data ''' db = connect.connect() cursor = db.cursor() cursor.execute(ESTS_QUERY, (serialno, courseno)) rows = cursor.fetchall() ests = [] for row in rows: hash_ = row[10] completed = bool(row[9]) tx_hash = TXHash(hash_, completed) ix = row[0] found = False # use existing est if one relates to multiple treatments for existing_est in ests: if existing_est.ix == ix: existing_est.tx_hashes.append(tx_hash) found = True break if found: continue # initiate a custom data class est = Estimate() est.ix = ix est.courseno = row[11] est.number = row[1] est.itemcode = row[2] est.description = row[3] est.fee = row[4] est.ptfee = row[5] est.feescale = row[6] est.csetype = row[7] est.dent = row[8] est.tx_hashes = [tx_hash] ests.append(est) cursor.close() return ests
def add_treatment_to_estimate(om_gui, att, shortcut, dentid, tx_hashes, itemcode=None, csetype=None, descr=None, fee=None, ptfee=None, chosen_feescale=None): ''' add an item to the patient's estimate usercode unnecessary if itemcode is provided. ''' def _tooth_code_search(att, shortcut): itemcode = table.getToothCode(att, shortcut) if itemcode != "-----": return itemcode, table LOGGER.debug("%s %s not matched by %s" % (att, shortcut, table)) for alt_table in localsettings.FEETABLES.tables.values(): if alt_table == table or not alt_table.is_current: continue alt_code = alt_table.getToothCode(att, shortcut) if alt_code != "-----": if QtWidgets.QMessageBox.question( om_gui, _("Confirm"), "<p><b>%s %s</b> %s.</p><p>%s <em>%s</em></p><hr />%s" % (att, shortcut, _("was not found in the patient's default feescale"), _("It is matched in another feescale -"), alt_table.briefName, _("Shall we add this item from this feescale?")), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.Yes ) == QtWidgets.QMessageBox.Yes: return alt_code, alt_table return itemcode, table def _user_code_search(usercode): itemcode = table.getItemCodeFromUserCode(usercode) if itemcode != "-----": return itemcode, table LOGGER.debug("%s not matched by %s" % (usercode, table)) for alt_table in localsettings.FEETABLES.tables.values(): if alt_table == table or not alt_table.is_current: continue alt_code = alt_table.getItemCodeFromUserCode(usercode) if alt_code != "-----": if QtWidgets.QMessageBox.question( om_gui, _("Confirm"), "<p><b>%s</b> %s.</p><p>%s <em>%s</em></p><hr />%s" % (usercode, _("was not found in the patient's " "default feescale"), _("It is matched in another feescale -"), alt_table.briefName, _("Shall we add this item from this feescale?")), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.Yes ) == QtWidgets.QMessageBox.Yes: return alt_code, alt_table return itemcode, table usercode = ("%s %s" % (att, shortcut)) LOGGER.debug("%s %s %s %s %s %s %s %s %s" % (usercode, dentid, tx_hashes, itemcode, csetype, descr, fee, ptfee, chosen_feescale)) for tx_hash in tx_hashes: assert isinstance(tx_hash, TXHash), "bad form Neil" pt = om_gui.pt est = Estimate() est.ix = None # -- this will be generated by autoincrement on commit est.serialno = pt.serialno est.courseno = pt.courseno0 if chosen_feescale is None: table = pt.fee_table else: table = chosen_feescale if re.match("[ul][lr][1-8A-E]", att): if itemcode is None: itemcode, table = _tooth_code_search(att, shortcut) if descr is None: tooth_name = att.upper() descr = table.getItemDescription(itemcode, usercode) descr = descr.replace("*", " %s" % tooth_name) else: if itemcode is None: itemcode, table = _user_code_search(usercode) if descr is None: descr = table.getItemDescription(itemcode, usercode) est.itemcode = itemcode est.description = descr est.csetype = table.categories[0] if fee is None and ptfee is None: # look up the fee here est.fee, est.ptfee = table.getFees(itemcode, pt, est.csetype, shortcut) else: est.fee, est.ptfee = fee, ptfee est.tx_hashes = tx_hashes est.dent = dentid pt.estimates.append(est) if itemcode == "-----": om_gui.advise( "%s - %s <b>%s</b><br />%s.<hr />%s" % (_("WARNING"), _("treatment"), usercode, _("has not been succesfully priced"), _("Please edit the estimate manually")), 1) return True