Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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'))
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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 []
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
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 []
Exemplo n.º 8
0
    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=3", database)
        if q_query.first():
            self.tooth_tx_id = q_query.value(0).toInt()[0]
Exemplo n.º 9
0
    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) * 8

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf('date_charted'))
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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'))
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
    def __init__(self, database):
        q_query = QtSql.QSqlQuery("select min(ix), max(ix) from patients",
                                  database)
        if q_query.first():
            min_patient_id = q_query.value(0).toInt()[0]
            max_patient_id = q_query.value(1).toInt()[0]
            self.patient_id = randint(min_patient_id, max_patient_id)
        else:
            self.patient_id = 0

        self.length = 1

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf('checked_date'))
        self.record.remove(self.record.indexOf('is_erupted'))
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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"))
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    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]
Exemplo n.º 22
0
class DemoGenerator(object):
    def __init__(self, database=None):
        self.length = 6

        self.record = InsertableRecord(database, TABLENAME)

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        for avatar in ("demo_neil.svg", "demo_andi.svg", "demo_blondie.svg",
                       "demo_helen.svg", "demo_me.svg", "demo_nattress.svg",
                       "demo_iceman.svg", "demo_frog.svg", "demo_jellyman.svg",
                       "demo_lucy.svg", "demo_negro.svg", "demo_ja.svg",
                       "demo_sally.svg"):
            f = QtCore.QFile(":avatars/%s" % avatar)
            f.open(QtCore.QIODevice.ReadOnly)
            ts = QtCore.QTextStream(f)

            self.record.clearValues()
            self.record.setValue("svg_data", ts.readAll())
            self.record.setValue("description", avatar)

            f.close()

            yield self.record.insert_query
Exemplo n.º 23
0
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
Exemplo n.º 24
0
    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'))
Exemplo n.º 25
0
    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
Exemplo n.º 26
0
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
Exemplo n.º 27
0
    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'))
Exemplo n.º 28
0
class DemoGenerator(object):
    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]

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        self.record.setValue('tooth_tx_id', self.tooth_tx_id)
        self.record.setValue('surfaces', "MO")
        self.record.setValue('material', "AM")
        sql = self.record.insert_query

        yield sql
Exemplo n.º 29
0
class DemoGenerator(object):
    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]

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        self.record.setValue('tooth_tx_id', self.tooth_tx_id)
        self.record.setValue('surfaces', "MO")
        self.record.setValue('material', "AM")
        sql = self.record.insert_query

        yield sql
    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 ix from practitioners
        where type='dentist' ''', database)

        self.dentist_ids = []
        while q_query.next():
            self.dentist_ids.append(q_query.value(0).toInt()[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('end_date'))
        self.record.remove(self.record.indexOf('start_date'))
    def __init__(self, database):
        q_query= QtSql.QSqlQuery(
            "select min(ix), max(ix) from patients", database)
        if q_query.first():
            min_patient_id = q_query.value(0).toInt()[0]
            max_patient_id = q_query.value(1).toInt()[0]
            self.patient_id = randint(min_patient_id, max_patient_id)
        else:
            self.patient_id = 0

        self.length = 1

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf('checked_date'))
        self.record.remove(self.record.indexOf('is_erupted'))
Exemplo n.º 32
0
    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)
Exemplo n.º 33
0
class DemoGenerator(object):
    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 telephone", database)
        if q_query.first():
            self.min_tel_id = q_query.value(0).toInt()[0]
            self.max_tel_id = q_query.value(1).toInt()[0]
        else:
            self.min_tel_id, self.max_tel_id = 0,0

        self.length = self.max_patient_id - self.min_patient_id

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf('tel_cat'))

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        sql_list = []
        for patient_id in xrange(self.min_patient_id, self.max_patient_id+1):
            self.record.clearValues()
            tel_id = (randint(self.min_tel_id, self.max_tel_id))

            #set values, or allow defaults
            self.record.setValue("patient_id", patient_id)
            self.record.setValue("tel_id", tel_id)

            sql_list.append(self.record.insert_query)

        return sql_list
Exemplo n.º 34
0
class DemoGenerator(object):
    def __init__(self, database):
        self.length = 1
        self.record = InsertableRecord(database, TABLENAME)

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        self.record.setValue('name', u"The Hogwarts Dental Clinic")
        self.record.setValue('website', u"http://en.wikipedia.org/wiki/Hogwarts")
        self.record.setValue('tel1', u"+44 1234 567890")
        self.record.setValue('address_ix', 1)
        sql = self.record.insert_query

        sql2 = '''INSERT INTO addresses
        (addr1, addr2, city, country, postal_cd, modified_by)
        VALUES (?,?,?,?,?,?)'''
        values = ('HOGWARTS SCHOOL OF WITCHCRAFT AND WIZARDRY',
        'THE FORBIDDEN FORREST', 'HOGSMEADE', 'SCOTLAND', 'HG1 1HG',
        'demo_installer')

        return [sql, (sql2, values)]
Exemplo n.º 35
0
    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)
    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 ix from practitioners
        where type='dentist' ''', database)

        self.dentist_ids = []
        while q_query.next():
            self.dentist_ids.append(q_query.value(0).toInt()[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('end_date'))
        self.record.remove(self.record.indexOf('start_date'))
Exemplo n.º 37
0
    def import_avatars(self):
        table_name = "avatars"
        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 avatars - no such file %s" %
                         filepath)
            raise _ImportWarning

        record = InsertableRecord(self.om2_session, table_name)

        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 ("description", "svg_data"):
                vals = row.getElementsByTagName(node)
                try:
                    val = vals[0].firstChild.data.strip()
                except IndexError:
                    val = None
                except AttributeError:
                    val = ""
                psql_query.addBindValue(val)

            psql_query.exec_()
            if psql_query.lastError().isValid():
                LOGGER.error("ERROR IMPORTING - %s" %
                             psql_query.lastError().text())
        self.register_progress("import_avatars", 100)
Exemplo n.º 38
0
class DemoGenerator(object):
    def __init__(self, database=None):
        self.database = database
        self.length = 1
        self.record = InsertableRecord(database, TABLENAME)

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''

        self.record.setValue('username', 'admin')
        self.record.setValue('password', 'password')
        self.record.setValue('comments',
'''This user has full read/write create rights to all tables.
It should not be used by anyone who is not aware of the havoc they could
cause by disturbing the database. Whenever you connect with this user,
make sure you have a full backup.
Even qualified DBAs make unrecoverable mistakes occasionally.
Also - Do not remove this user!''')

        yield self.record.insert_query
Exemplo n.º 39
0
class DemoGenerator(object):
    def __init__(self, database=None):
        self.database = database
        self.length = 1
        self.record = InsertableRecord(database, TABLENAME)

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''

        self.record.setValue('username', 'admin')
        self.record.setValue('password', 'password')
        self.record.setValue(
            'comments',
            '''This user has full read/write create rights to all tables.
It should not be used by anyone who is not aware of the havoc they could
cause by disturbing the database. Whenever you connect with this user,
make sure you have a full backup.
Even qualified DBAs make unrecoverable mistakes occasionally.
Also - Do not remove this user!''')

        yield self.record.insert_query
Exemplo n.º 40
0
class DemoGenerator(object):
    def __init__(self, database=None):
        self.length = 6

        self.record = InsertableRecord(database, TABLENAME)

    def demo_queries(self):
        """
        return a list of queries to populate a demo database
        """
        for avatar in (
            "demo_neil.svg",
            "demo_andi.svg",
            "demo_blondie.svg",
            "demo_helen.svg",
            "demo_me.svg",
            "demo_nattress.svg",
            "demo_iceman.svg",
            "demo_frog.svg",
            "demo_jellyman.svg",
            "demo_lucy.svg",
            "demo_negro.svg",
            "demo_ja.svg",
            "demo_sally.svg",
        ):
            f = QtCore.QFile(":avatars/%s" % avatar)
            f.open(QtCore.QIODevice.ReadOnly)
            ts = QtCore.QTextStream(f)

            self.record.clearValues()
            self.record.setValue("svg_data", ts.readAll())
            self.record.setValue("description", avatar)

            f.close()

            yield self.record.insert_query
Exemplo n.º 41
0
class DemoGenerator(object):
    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)
        self.record.remove(self.record.indexOf('checked_date'))

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        unique_roots = set([])
        while len(unique_roots) < self.length:
            pt = randint(self.min_patient_id, self.max_patient_id)
            root = randint(1, 32)
            unique_roots.add((pt, root))

        for pt, root in unique_roots:
            self.record.clearValues()
            #set values, or allow defaults
            self.record.setValue('patient_id', pt)
            self.record.setValue('tooth', root)
            self.record.setValue('checked_by', 'demo_installer')
            self.record.setValue('values', "YNYNYN")

            yield self.record.insert_query
Exemplo n.º 42
0
    def __init__(self, database):
        self.length = 4

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf("date_issued"))
        self.record.remove(self.record.indexOf("discount"))
Exemplo n.º 43
0
class DemoGenerator(object):
    def __init__(self, database):
        self.length = 4

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf("date_issued"))
        self.record.remove(self.record.indexOf("discount"))

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('status_id', 1)
        self.record.setValue('total_fees', 20.50)
        self.record.setValue('amount_payable', 20.50)
        yield self.record.insert_query

        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('status_id', 2)
        self.record.setValue('total_fees', 4.50)
        self.record.setValue('amount_payable', 4.50)
        yield self.record.insert_query
Exemplo n.º 44
0
class DemoGenerator(object):
    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'))

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''

        for pt in range(self.min_patient_id, self.max_patient_id):
            self.record.clearValues()
            #set values, or allow defaults
            self.record.setValue('patient_id', pt)
            self.record.setValue('checked_by', 'demo_installer')
            self.record.setValue('values', "1234*-")

            yield self.record.insert_query
Exemplo n.º 45
0
class DemoGenerator(object):
    def __init__(self, database):
        self.length = 4

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf("time_stamp"))

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('fee', 20.50)
        self.record.setValue('type', 'treatment')
        yield self.record.insert_query

        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('fee', 4.50)
        self.record.setValue('type', 'sundries')
        yield self.record.insert_query
Exemplo n.º 46
0
    def __init__(self, database):
        self.length = 4

        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf("time_stamp"))
Exemplo n.º 47
0
 def __init__(self):
     InsertableRecord.__init__(self, SETTINGS.psql_conn, TABLENAME)
Exemplo n.º 48
0
    def __init__(self, database):
        self.length = 44

        self.record = InsertableRecord(database, TABLENAME)
Exemplo n.º 49
0
class DemoGenerator(object):
    def __init__(self, database=None):
        self.length = 2
        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf("active"))

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        year = QtCore.QDate.currentDate().year()

        for id in range(1, 3):
            self.record.clearValues()
            self.record.setValue('user_id', id)
            self.record.setValue('book_start', QtCore.QDate(year, 1, 1))
            self.record.setValue('book_end', QtCore.QDate(year + 2, 1, 1))
            self.record.setValue('comment', 'demo diary')
            yield self.record.insert_query
Exemplo n.º 50
0
class NotesClinicalDB(object):
    _new_note = None
    _records = None

    def __init__(self, patient_id):
        #:
        self.patient_id = patient_id

    @property
    def is_dirty(self):
        ## todo - this does not allow for a commited note or an edited note
        if self._new_note is None:
            return False
        return self._new_note.value("line").toString() != ""

    @property
    def has_new_note(self):
        return self._new_note is not None

    @property
    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

    def commit_note(self, note):
        '''
        note has been updated
        '''
        if not note in self._records:
            self._records.append(self._new_note)
        return True

    def get_records(self):
        '''
        get the records from the database

        .. note:
            A property of is_clinical is added to each record, and set as True
        '''
        self._records = []
        query = 'SELECT * from %s WHERE patient_id = ? order by open_time' % (
            TABLENAME)
        q_query = QtSql.QSqlQuery(SETTINGS.psql_conn)
        q_query.prepare(query)
        q_query.addBindValue(self.patient_id)
        q_query.exec_()
        while q_query.next():
            record = q_query.record()
            record.is_clinical = True
            self._records.append(record)

    @property
    def records(self):
        '''
        returns a list of all records (type QtSql.QSqlRecords) found
        '''
        if self._records is None:
            self.get_records()
        return self._records

    def record_by_id(self, id):
        '''
        return the text of the record with a specific id
        '''
        for record in self.records:
            if record.value(0) == id:
                return record
        print "ERROR - clinical note record %d not found in memory" % id
        return None
Exemplo n.º 51
0
 def __init__(self, database=None):
     self.length = 2
     self.record = InsertableRecord(database, TABLENAME)
     self.record.remove(self.record.indexOf("active"))
Exemplo n.º 52
0
class DemoGenerator(object):
    def __init__(self, database=None):
        self.database = database
        self.length = 3
        self.record = InsertableRecord(database, TABLENAME)
        self.record.remove(self.record.indexOf("trt2"))
        self.record.remove(self.record.indexOf("memo"))

    def get_diary_id(self):
        '''
        poll the database for the demo exam diary_entry
        '''
        LOGGER.debug("polling diary_entries table for an appointment")
        q_query= QtSql.QSqlQuery(
            "select ix from diary_entries where etype='appointment' limit 1",
            self.database)
        if q_query.first():
            return q_query.value(0).toInt()[0]
        else:
            LOGGER.warning("No exam appointment found in diary table")
            return None

    def demo_queries(self):
        '''
        return a list of queries to populate a demo database
        '''
        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('trt1', "exam")
        self.record.setValue('len', 15)
        self.record.setValue('preferred_practitioner', 1)
        self.record.setValue('diary_entry_id', self.get_diary_id())
        yield self.record.insert_query

        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('trt1', "fill")
        self.record.setValue('len', 30)
        self.record.setValue('preferred_practitioner', 1)
        yield self.record.insert_query

        self.record.clearValues()
        self.record.setValue('patient_id', 1)
        self.record.setValue('trt1', "hyg")
        self.record.setValue('len', 30)
        self.record.setValue('preferred_practitioner', 3)
        yield self.record.insert_query
Exemplo n.º 53
0
 def __init__(self, database=None):
     self.database = database
     self.length = 3
     self.record = InsertableRecord(database, TABLENAME)
     self.record.remove(self.record.indexOf("trt2"))
     self.record.remove(self.record.indexOf("memo"))