本文整理汇总了Python中lib_openmolar.common.db_orm.InsertableRecord类的典型用法代码示例。如果您正苦于以下问题:Python InsertableRecord类的具体用法?Python InsertableRecord怎么用?Python InsertableRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InsertableRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_users
def import_users(self, ignore_errors=False):
table_name = "users"
LOGGER.info("importing %s"% table_name)
try:
filepath = os.path.abspath(
os.path.join(self.import_directory, "%s.xml"% table_name))
dom = minidom.parse(filepath)
except IOError:
LOGGER.error(
"Unable to import users - no such file %s"% filepath)
raise self.ImportWarning
record = InsertableRecord(self.om2_session, table_name)
record.include_ix = True
record.remove(record.indexOf("time_stamp"))
ps_query, values = record.insert_query
psql_query = QtSql.QSqlQuery(self.om2_session)
rows = dom.getElementsByTagName(table_name.rstrip("s"))
errors_encountered = False
for row in rows:
psql_query.prepare(ps_query)
for node in ('ix', 'abbrv_name', 'role', 'title', 'last_name',
'middle_name', 'first_name', 'qualifications', 'registration',
'correspondence_name', 'sex', 'dob',
'status', 'comments', 'avatar_id', 'display_order'):
vals = row.getElementsByTagName(node)
try:
val = vals[0].firstChild.data.strip()
if node == "ix":
ix = int(val)
elif node == "abbrv_name":
user = val
self.USER_DICT[user] = ix
except IndexError:
val = None
except AttributeError:
val = ""
psql_query.addBindValue(val)
psql_query.addBindValue("imported from xml")
psql_query.exec_()
if not ignore_errors and psql_query.lastError().isValid():
LOGGER.warning("ERROR IMPORTING User \n\t%s\t%s"% (
row.toprettyxml(),
psql_query.lastError().text()))
errors_encountered = True
LOGGER.debug(self.USER_DICT)
if errors_encountered:
raise self.ImportWarning
self.register_progress("import_users", 100)
示例2: DemoGenerator
class DemoGenerator(object):
def __init__(self, database=None):
q_query= QtSql.QSqlQuery(
'''select ix from patients
where last_name='POTTER' and first_name='HARRY' ''', database)
self.length = 0
self.patient_id = None
if q_query.first():
self.length = 1
self.patient_id = q_query.value(0).toInt()[0]
self.record = InsertableRecord(database, TABLENAME)
self.record.remove(self.record.indexOf('checked_date'))
def demo_queries(self):
'''
return a list of queries to populate a demo database
'''
if self.patient_id:
self.record.setValue('patient_id', self.patient_id)
self.record.setValue('memo', "legal guardian is Mr Vernon Dursley")
self.record.setValue('checked_by', 'demo_installer')
return [self.record.insert_query]
return []
示例3: DemoGenerator
class DemoGenerator(object):
def __init__(self, database):
q_query = QtSql.QSqlQuery(
"""select ix from patients
where last_name='POTTER' and first_name='HARRY' """,
database,
)
self.length = 0
self.patient_id = None
if q_query.first():
self.length = 1
self.patient_id = q_query.value(0).toInt()[0]
self.record = InsertableRecord(database, TABLENAME)
self.record.remove(self.record.indexOf("checked_date"))
def demo_queries(self):
"""
return a list of queries to populate a demo database
"""
sql_list = []
if self.patient_id:
self.record.setValue("patient_id", self.patient_id)
self.record.setValue("memo", "Nasty scar on forehead, present since birth")
self.record.setValue("checked_by", "demo_installer")
sql_list.append(self.record.insert_query)
return sql_list
示例4: DemoGenerator
class DemoGenerator(object):
def __init__(self, database=None):
self.length = 820
self.record = InsertableRecord(database, TABLENAME)
def demo_queries(self):
'''
return a list of queries to populate a demo database
'''
date_ = QtCore.QDate.currentDate().addMonths(-1)
finish_date = date_.addMonths(6)
while date_ < finish_date:
dayno = date_.dayOfWeek()
if dayno in (6,7):
date_ = date_.addDays(1)
continue
if dayno == 2:
start = QtCore.QDateTime(date_, QtCore.QTime(13,0))
end_ = QtCore.QDateTime(date_, QtCore.QTime(19,0))
else:
start = QtCore.QDateTime(date_, QtCore.QTime(9,0))
end_ = QtCore.QDateTime(date_, QtCore.QTime(17,0))
self.record.clearValues()
self.record.setValue('diary_id', 1)
self.record.setValue('start', start)
self.record.setValue('finish', end_)
self.record.setValue('comment', 'demo session')
yield self.record.insert_query
date_ = date_.addDays(1)
示例5: DemoGenerator
class DemoGenerator(object):
def __init__(self, database):
self.length = 2
self.record = InsertableRecord(database, TABLENAME)
def demo_queries(self):
'''
return a list of queries to populate a demo database
'''
for i in range(self.length):
self.record.clearValues()
self.record.setValue('status', 'open')
yield self.record.insert_query
示例6: __init__
def __init__(self, database=None):
q_query = QtSql.QSqlQuery("select min(ix), max(ix) from patients", database)
if q_query.first():
self.min_patient_id = q_query.value(0).toInt()[0]
self.max_patient_id = q_query.value(1).toInt()[0]
else:
self.min_patient_id, self.max_patient_id = 0, 0
q_query = QtSql.QSqlQuery("select min(ix), max(ix) from addresses", database)
if q_query.first():
self.max_address_id = q_query.value(1).toInt()[0]
self.min_address_id = q_query.value(0).toInt()[0]
# reserve id number 1 for the practice address.
if self.min_address_id == 1 and self.max_address_id > 1:
self.min_address_id == 2
else:
self.min_address_id, self.max_address_id = 0, 0
self.length = self.max_patient_id - self.min_patient_id
self.record = InsertableRecord(database, TABLENAME)
self.record.remove(self.record.indexOf("address_cat"))
self.record.remove(self.record.indexOf("to_date"))
self.record.remove(self.record.indexOf("from_date"))
self.record.remove(self.record.indexOf("mailing"))
示例7: __init__
def __init__(self, database=None):
q_query= QtSql.QSqlQuery(
"select min(ix), max(ix) from patients", database)
if q_query.first():
self.min_patient_id = q_query.value(0).toInt()[0]
self.max_patient_id = q_query.value(1).toInt()[0]
else:
self.min_patient_id, self.max_patient_id = 0,0
self.clinicians = []
q_query= QtSql.QSqlQuery(
"select user_id from view_practitioners", database)
while q_query.next():
self.clinicians.append(q_query.value(0).toInt()[0])
self.authors = []
q_query= QtSql.QSqlQuery(
"select ix from users", database)
while q_query.next():
self.authors.append(q_query.value(0).toInt()[0])
for clinician in self.clinicians:
self.authors.remove(clinician)
self.length = 500
self.record = InsertableRecord(database, TABLENAME)
示例8: __init__
def __init__(self, patient_id):
InsertableRecord.__init__(self, SETTINGS.psql_conn,
TABLENAME)
#:
self.patient_id = patient_id
query = '''SELECT * from %s WHERE patient_id = ?
order by ix desc limit 1'''% TABLENAME
q_query = QtSql.QSqlQuery(SETTINGS.psql_conn)
q_query.prepare(query)
q_query.addBindValue(patient_id)
q_query.exec_()
q_query.next()
record = q_query.record()
QtSql.QSqlQuery.__init__(self, record)
## make a copy (a marker of database state)
self.orig = QtSql.QSqlRecord()
QtSql.QSqlQuery.__init__(self.orig, record)
示例9: import_practitioners
def import_practitioners(self):
table_name = "practitioners"
LOGGER.info("importing %s"% table_name)
try:
filepath = os.path.abspath(
os.path.join(self.import_directory, "%s.xml"% table_name))
dom = minidom.parse(filepath)
except IOError as exc:
LOGGER.error(
"Unable to import practitioners - no such file %s"% filepath)
raise _ImportWarning
record = InsertableRecord(self.om2_session, table_name)
record.include_ix = True
record.remove(record.indexOf("time_stamp"))
ps_query, values = record.insert_query
psql_query = QtSql.QSqlQuery(self.om2_session)
rows = dom.getElementsByTagName(table_name.rstrip("s"))
for row in rows:
psql_query.prepare(ps_query)
for node in ("ix", "user_id", "type", "speciality",
"status", "comments", ):
vals = row.getElementsByTagName(node)
try:
val = vals[0].firstChild.data.strip()
except IndexError:
val = None
except AttributeError:
val = ""
psql_query.addBindValue(val)
psql_query.addBindValue("imported from xml")
psql_query.exec_()
if psql_query.lastError().isValid():
LOGGER.warning("ERROR IMPORTING %s - %s"% (
row.toxml(),
psql_query.lastError().text()))
self.register_progress("import_practitioners", 100)
示例10: __init__
def __init__(self, database=None):
self.length = 1
self.record = InsertableRecord(database, TABLENAME)
self.tooth_tx_id = 0
q_query= QtSql.QSqlQuery(
"select ix from treatment_teeth where treatment_id=2", database)
if q_query.first():
self.tooth_tx_id = q_query.value(0).toInt()[0]
示例11: DemoGenerator
class DemoGenerator(object):
def __init__(self, database):
self.length = 40
self.record = InsertableRecord(database, TABLENAME)
self.record.remove(self.record.indexOf('checked_date'))
def demo_queries(self):
'''
return a list of queries to populate a demo database
'''
for i in range(self.length):
self.record.clearValues()
#set values, or allow defaults
self.record.setValue('number',
u"0%04d %06d"% (randint(1000,9999), randint(100000,999999)))
self.record.setValue('checked_by', "demo_installer")
yield self.record.insert_query
示例12: new_note
def new_note(self):
if self._new_note is None:
print "creating new clinical note with authors %s and %s"% (
SETTINGS.user1, SETTINGS.user2)
self._new_note = InsertableRecord(SETTINGS.psql_conn, TABLENAME)
self._new_note.is_clinical = True
self._new_note.setValue("open_time", QtCore.QDateTime.currentDateTime())
if SETTINGS.user1:
self._new_note.setValue("author", SETTINGS.user1.id)
if SETTINGS.user2:
self._new_note.setValue("co-author", SETTINGS.user2.id)
return self._new_note
示例13: __init__
def __init__(self, database=None):
q_query= QtSql.QSqlQuery(
"select min(ix), max(ix) from patients", database)
if q_query.first():
self.min_patient_id = q_query.value(0).toInt()[0]
self.max_patient_id = q_query.value(1).toInt()[0]
else:
self.min_patient_id, self.max_patient_id = 0,0
self.length = self.max_patient_id - self.min_patient_id
self.record = InsertableRecord(database, TABLENAME)
self.record.remove(self.record.indexOf('checked_date'))
示例14: __init__
def __init__(self, database=None):
q_query= QtSql.QSqlQuery(
'''select ix from patients
where last_name='POTTER' and first_name='HARRY' ''', database)
self.length = 0
self.patient_id = None
if q_query.first():
self.length = 1
self.patient_id = q_query.value(0).toInt()[0]
self.record = InsertableRecord(database, TABLENAME)
self.record.remove(self.record.indexOf('checked_date'))
示例15: __init__
def __init__(self, database=None):
q_query= QtSql.QSqlQuery(
"select min(ix), max(ix) from patients", database)
if q_query.first():
self.min_patient_id = q_query.value(0).toInt()[0]
self.max_patient_id = q_query.value(1).toInt()[0]
else:
self.min_patient_id, self.max_patient_id = 0,0
self.length = (self.max_patient_id - self.min_patient_id) * 24
if self.length > 100:
self.length = 100
self.record = InsertableRecord(database, TABLENAME)