def toNotes(serialno, newnotes):
    '''
    new code with schema 1.9
    '''
    LOGGER.debug("write changes - toNotes for patient %d" % serialno)

    # database version stores max line length of 80chars

    query = '''insert into formatted_notes
    (serialno, ndate, op1, op2, ntype, note)
    VALUES (%s, DATE(NOW()), %s, %s, %s, %s)
    '''
    notetuplets = []

    tstamp = localsettings.currentTime().strftime("%d/%m/%Y %T")
    notetuplets.append(
        ("opened", "System date - %s" % tstamp))
    for ntype, note in newnotes:
        while len(note) > 79:
            if " " in note[:79]:
                pos = note[:79].rindex(" ")
                #--try to split nicely
            elif "," in note[:79]:
                pos = note[:79].rindex(",")
                #--try to split nicely
            else:
                pos = 79
                #--ok, no option (unlikely to happen though)
            notetuplets.append((ntype, note[:pos]))
            note = note[pos + 1:]

        notetuplets.append((ntype, note + "\n"))
    notetuplets.append(
        ("closed", "%s %s" % (localsettings.operator, tstamp)))

    values = []
    ops = localsettings.operator.split("/")
    op1 = ops[0]
    try:
        op2 = ops[1]
    except IndexError:
        op2 = None
    for ntype, noteline in notetuplets:
        values.append((serialno, op1, op2, ntype, noteline))

    rows = 0
    if values:
        db = connect()
        cursor = db.cursor()

        # this (superior code?) didn't work on older MySQLdb versions.
        # rows = cursor.executemany(query, tuple(values))
        for value in values:
            rows += cursor.execute(query, value)

        cursor.close()
        db.commit()

    return rows > 0
Example #2
0
def toNotes(serialno, newnotes):
    '''
    new code with schema 1.9
    '''
    LOGGER.debug("write changes - toNotes for patient %d" % serialno)

    # database version stores max line length of 80chars

    query = '''insert into formatted_notes
    (serialno, ndate, op1, op2, ntype, note)
    VALUES (%s, DATE(NOW()), %s, %s, %s, %s)
    '''
    notetuplets = []

    tstamp = localsettings.currentTime().strftime("%d/%m/%Y %T")
    notetuplets.append(("opened", "System date - %s" % tstamp))
    for ntype, note in newnotes:
        while len(note) > 79:
            if " " in note[:79]:
                pos = note[:79].rindex(" ")
                #--try to split nicely
            elif "," in note[:79]:
                pos = note[:79].rindex(",")
                #--try to split nicely
            else:
                pos = 79
                #--ok, no option (unlikely to happen though)
            notetuplets.append((ntype, note[:pos]))
            note = note[pos + 1:]

        notetuplets.append((ntype, note + "\n"))
    notetuplets.append(("closed", "%s %s" % (localsettings.operator, tstamp)))

    values = []
    ops = localsettings.operator.split("/")
    op1 = ops[0]
    try:
        op2 = ops[1]
    except IndexError:
        op2 = None
    for ntype, noteline in notetuplets:
        values.append((serialno, op1, op2, ntype, noteline))

    rows = 0
    if values:
        db = connect()
        cursor = db.cursor()

        # this (superior code?) didn't work on older MySQLdb versions.
        # rows = cursor.executemany(query, tuple(values))
        for value in values:
            rows += cursor.execute(query, value)

        cursor.close()
        db.commit()

    return rows > 0
def toNotes(serialno, newnotes):
    '''
    new code with schema 1.9
    '''
    LOGGER.debug("write changes - toNotes for patient %d" % serialno)

    tstamp = localsettings.currentTime().strftime("%d/%m/%Y %H:%M:%S")

    notetuplets = []
    notetuplets.append(("opened", "System date - %s" % tstamp))

    # database version stores max line length of 80chars
    for ntype, notes in newnotes:
        line_end = "\n" if ntype == "newNOTE" else ""
        for line in note_splitter(notes, line_end):
            notetuplets.append((ntype, line))
    notetuplets.append(("closed", "%s %s" % (localsettings.operator, tstamp)))

    try:
        op1, op2 = localsettings.operator.split("/")
    except ValueError:
        op1 = localsettings.operator
        op2 = None

    values = []
    for ntype, noteline in notetuplets:
        values.append((serialno, op1, op2, ntype, noteline))

    rows = 0
    if values:
        db = connect()
        cursor = db.cursor()
        # this (superior code?) didn't work on older MySQLdb versions.
        # rows = cursor.executemany(query, tuple(values))
        for value in values:
            rows += cursor.execute(INSERT_NOTE_QUERY, value)
        cursor.close()
        db.commit()

    return rows > 0
def toNotes(serialno, newnotes):
    '''
    new code with schema 1.9
    '''
    LOGGER.debug("write changes - toNotes for patient %d" % serialno)

    tstamp = localsettings.currentTime().strftime("%d/%m/%Y %H:%M:%S")

    notetuplets = []
    notetuplets.append(("opened", "System date - %s" % tstamp))

    # database version stores max line length of 80chars
    for ntype, notes in newnotes:
        line_end = "\n" if ntype == "newNOTE" else ""
        for line in note_splitter(notes, line_end):
            notetuplets.append((ntype, line))
    notetuplets.append(("closed", "%s %s" % (localsettings.operator, tstamp)))

    try:
        op1, op2 = localsettings.operator.split("/")
    except ValueError:
        op1 = localsettings.operator
        op2 = None

    values = []
    for ntype, noteline in notetuplets:
        values.append((serialno, op1, op2, ntype, noteline))

    rows = 0
    if values:
        db = connect()
        cursor = db.cursor()
        # this (superior code?) didn't work on older MySQLdb versions.
        # rows = cursor.executemany(query, tuple(values))
        for value in values:
            rows += cursor.execute(INSERT_NOTE_QUERY, value)
        cursor.close()
        db.commit()

    return rows > 0
Example #5
0
def loadForum(om_gui):
    '''
    loads the forum
    '''
    twidg = om_gui.ui.forum_treeWidget
    twidg.clear()
    twidg.setSortingEnabled(False)
    chosen = om_gui.ui.forumViewFilter_comboBox.currentText()
    GROUP_TOPICS = om_gui.ui.group_replies_radioButton.isChecked()
    #-- set the column headers (stored in another module)
    headers = forum.headers
    twidg.setHeaderLabels(headers)
    #-- get the posts
    show_closed = om_gui.ui.forum_deletedposts_checkBox.isChecked()
    if chosen != _("Everyone"):
        posts = forum.getPosts(chosen, show_closed)
    else:
        posts = forum.getPosts(None, show_closed)

    parentItems = {None: twidg}

    #--set a boolean for alternating row colours
    highlighted = True
    for post in posts:
        if GROUP_TOPICS:
            parentItem = parentItems.get(post.parent_ix, twidg)
        else:
            parentItem = twidg
        item = QtGui.QTreeWidgetItem(parentItem)
        item.setText(0, post.topic)
        item.setData(1, QtCore.Qt.DisplayRole, post.ix)
        item.setText(2, post.inits)
        if post.recipient:
            item.setText(3, post.recipient)
        else:
            item.setText(3, "-")

        d = QtCore.QDateTime(post.date)
        item.setData(4, QtCore.Qt.DisplayRole, QtCore.QVariant(d))

        item.setText(5, post.comment)
        item.setText(6, post.briefcomment)
        # item.setData(7, QtCore.Qt.DisplayRole, post.parent_ix)

        # if parentItem == twidg:
        #    highlighted = not highlighted
        #    if highlighted:
        #        bcolour = twidg.palette().base()
        #    else:
        #        bcolour = twidg.palette().alternateBase()
        # else:
        # bcolour = QtGui.QColor("red")#parentItem.background(0)

        if parentItem == twidg:
            item.setIcon(0, om_gui.ui.forumNewTopic_pushButton.icon())

        for i in range(item.columnCount()):
            # item.setBackground(i,bcolour)
            if i == 4:  # date
                if post.date > (localsettings.currentTime() -
                                datetime.timedelta(hours=36)):
                    item.setIcon(i, om_gui.ui.forumNewTopic_pushButton.icon())
                    item.setTextColor(i, QtGui.QColor("orange"))
                # TODO - put in some code to set the text for "today"
                # or yesterday etc...
        if GROUP_TOPICS:
            parentItems[post.ix] = item

    twidg.expandAll()

    twidg.setSortingEnabled(True)
    # if GROUP_TOPICS:
    #    twidg.sortByColumn(7)
    # else:
    twidg.sortByColumn(4, QtCore.Qt.AscendingOrder)

    for i in range(twidg.columnCount()):
        twidg.resizeColumnToContents(i)
    twidg.setColumnWidth(1, 0)
    twidg.setColumnWidth(5, 0)
    # twidg.setColumnWidth(7, 0)

    om_gui.ui.forumDelete_pushButton.setEnabled(False)
    om_gui.ui.forumReply_pushButton.setEnabled(False)
    om_gui.ui.forumParent_pushButton.setEnabled(False)