Example #1
0
    def __init_from_pk(self, aPK_obj=None, link_obj=None):
        """Creates a new clinical item instance by its PK.

		aPK_obj can be:
			- a simple value
			  * the primary key WHERE condition must be
				a simple column
			- a dictionary of values
			  * the primary key where condition must be a
				subselect consuming the dict and producing
				the single-value primary key
		"""
        self.pk_obj = aPK_obj
        result = self.refetch_payload(link_obj=link_obj)
        if result is True:
            self.payload_most_recently_fetched = {}
            for field in self._idx.keys():
                self.payload_most_recently_fetched[field] = self._payload[
                    self._idx[field]]
            return True

        if result is False:
            raise gmExceptions.ConstructorError(
                "[%s:%s]: error loading instance" %
                (self.__class__.__name__, self.pk_obj))
Example #2
0
    def __init__(self, parent, size, input_defs=None, problem=None):
        """Resizing SOAP note input editor.

		This is a wrapper around a few resizing STCs (the
		labels and categories are settable) which are
		customized to accept progress note input. It provides
		the unified resizing behaviour.

		Knows how to save it's data into the backend.

		@param input_defs: note's labels and categories
		@type input_defs: list of cSOAPLineDef instances
		"""
        if input_defs is None or len(input_defs) == 0:
            raise gmExceptions.ConstructorError(
                'cannot generate note with field defs [%s]' % input_defs)

        # FIXME: *actually* this should be a session-local
        # FIXME: holding store at the c_ClinicalRecord level
        self.__embedded_data_holder = cPopupDataHolder()

        self.__input_defs = input_defs

        gmResizingWidgets.cResizingWindow.__init__(self,
                                                   parent,
                                                   id=-1,
                                                   size=size)

        self.__problem = problem
        if isinstance(problem, gmEMRStructItems.cEpisode):
            self.__problem = emr.episode2problem(episode=problem)
        elif isinstance(problem, gmEMRStructItems.cHealthIssue):
            self.__problem = emr.health_issue2problem(issue=problem)
        self.__pat = gmPerson.gmCurrentPatient()
Example #3
0
    def __init__(self, parent, size, input_defs=None, problem=None):
        """Initialize SOAP note input editor.

		@param input_defs: note's labels and categories
		@type input_defs: list of cSOAPLineDef instances
		"""
        if input_defs is None or len(input_defs) == 0:
            raise gmExceptions.ConstructorError(
                'cannot generate note with field defs [%s]' % input_defs)

        # FIXME: *actually* this should be a session-local
        # FIXME: holding store at the c_ClinicalRecord level
        self.__embedded_data_holder = cPopupDataHolder()

        self.__input_defs = input_defs

        gmResizingWidgets.cResizingWindow.__init__(self,
                                                   parent,
                                                   id=-1,
                                                   size=size)

        self.__problem = problem
        if isinstance(problem, gmEMRStructItems.cEpisode):
            self.__problem = gmEMRStructItems.episode2problem(episode=problem)
        elif isinstance(problem, gmEMRStructItems.cHealthIssue):
            self.__problem = gmEMRStructItems.health_issue2problem(
                issue=problem)
        self.__pat = gmPerson.gmCurrentPatient()
Example #4
0
    def __init__(self):
        # detect KOrganizer
        found, cmd = gmShellAPI.detect_external_binary(
            binary='konsolekalendar')
        if not found:
            raise gmExceptions.ConstructorError(
                'cannot detect "konsolekalendar" via [%s]' % cmd)

        gmPlugin.cNotebookPlugin.__init__(self)
Example #5
0
    def _init_from_row_data(self, row=None):
        """Creates a new clinical item instance given its fields.

		row must be a dict with the fields:
			- pk_field: the name of the primary key field
			- idx: a dict mapping field names to position
			- data: the field values in a list (as returned by
			  cursor.fetchone() in the DB-API)

		row = {'data': rows[0], 'idx': idx, 'pk_field': 'pk_XXX (the PK column name)'}

		rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': args}], get_col_idx = True)
		objects = [ cChildClass(row = {'data': r, 'idx': idx, 'pk_field': 'the PK column name'}) for r in rows ]
		"""
        try:
            self._idx = row['idx']
            self._payload = row['data']
            self.pk_obj = self._payload[self._idx[row['pk_field']]]
        except:
            _log.exception('faulty <row> argument structure: %s' % row)
            raise gmExceptions.ConstructorError(
                "[%s:??]: error loading instance from row data" %
                self.__class__.__name__)

        if len(self._idx.keys()) != len(self._payload):
            _log.critical(
                'field index vs. payload length mismatch: %s field names vs. %s fields'
                % (len(self._idx.keys()), len(self._payload)))
            _log.critical('faulty <row> argument structure: %s' % row)
            raise gmExceptions.ConstructorError(
                "[%s:??]: error loading instance from row data" %
                self.__class__.__name__)

        self.payload_most_recently_fetched = {}
        for field in self._idx.keys():
            self.payload_most_recently_fetched[field] = self._payload[
                self._idx[field]]
Example #6
0
	def __init__(self, aPKey = None):
		"""Fails if

		- patient referenced by aPKey does not exist
		"""
		self.pk_patient = aPKey			# == identity.pk == primary key
		if not self._pkey_exists():
			raise gmExceptions.ConstructorError("No patient with PK [%s] in database." % aPKey)

		# register backend notification interests
		# (keep this last so we won't hang on threads when
		#  failing this constructor for other reasons ...)
#		if not self._register_interests():
#			raise gmExceptions.ConstructorError, "cannot register signal interests"

		_log.debug('instantiated document folder for patient [%s]' % self.pk_patient)
Example #7
0
    def __init__(self, parent, id):
        """Set up our specialised grid.
		"""
        # get connection
        self.__backend = gmPG2.ConnectionPool()
        self.__defconn = self.__backend.GetConnection('blobs')
        if self.__defconn is None:
            _log.error(
                "Cannot retrieve lab data without database connection !")
            raise gmExceptions.ConstructorError(
                "cLabDataGrid.__init__(): need db conn")

        wx.Grid.__init__(self,
                         parent,
                         id,
                         pos=wx.DefaultPosition,
                         size=wx.DefaultSize,
                         style=wx.WANTS_CHARS)

        self.__pat = gmPerson.gmCurrentPatient()

        #wx.EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)

        # create new grid
        self.__grid_unreviewed_results = self.CreateGrid(
            0, 0, wx.Grid.wx.GridSelectCells)
        self.SetDefaultCellAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
        #renderer = apply(wxGridCellStringRenderer, ())
        renderer = None
        self.SetDefaultRenderer(renderer)

        # There is a bug in wxGTK for this method...
        self.AutoSizeColumns(True)
        self.AutoSizeRows(True)
        # attribute objects let you keep a set of formatting values
        # in one spot, and reuse them if needed
        font = self.GetFont()
        #font.SetWeight(wx.BOLD)
        attr = wx.GridCellAttr()
        attr.SetFont(font)
        #attr.SetBackgroundColour(wx.LIGHT_GREY)
        attr.SetReadOnly(True)
Example #8
0
    def __init__(self, parent, problem=None, input_defs=None):
        """
		Construct a new SOAP input widget.

		@param parent: the parent widget

		@param episode: the episode to create the SOAP editor for.
		@type episode gmEMRStructItems.cEpisode instance or None (to create an
		unassociated progress note). A gmEMRStructItems.cProblem instance is 
		also allowed to be passed, as the widget will obtain the related cEpisode.

		@param input_defs: the display and associated data for each displayed narrative
		@type input_defs: a list of cSOAPLineDef instances
		"""
        if not isinstance(
                problem,
            (gmEMRStructItems.cHealthIssue, gmEMRStructItems.cEpisode,
             gmEMRStructItems.cProblem, type(None))):
            raise gmExceptions.ConstructorError(
                'problem [%s] is of type %s, must be issue, episode, problem or None'
                % (str(problem), type(problem)))

        self.__is_saved = False
        # do layout
        wx.Panel.__init__(self,
                          parent,
                          -1,
                          style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
        # - editor
        if input_defs is None:
            soap_lines = []
            # make Richard the default ;-)
            # FIXME: actually, should be read from backend
            line = cSOAPLineDef()
            line.label = _('Visit Purpose')
            line.soap_cat = 's'
            line.is_rfe = True
            soap_lines.append(line)

            line = cSOAPLineDef()
            line.label = _('History Taken')
            line.soap_cat = 's'
            soap_lines.append(line)

            line = cSOAPLineDef()
            line.label = _('Findings')
            line.soap_cat = 'o'
            soap_lines.append(line)

            line = cSOAPLineDef()
            line.label = _('Assessment')
            line.soap_cat = 'a'
            soap_lines.append(line)

            line = cSOAPLineDef()
            line.label = _('Plan')
            line.soap_cat = 'p'
            soap_lines.append(line)
        else:
            soap_lines = input_defs
        self.__soap_editor = cResizingSoapWin(self,
                                              size=wx.DefaultSize,
                                              input_defs=soap_lines,
                                              problem=problem)
        # - arrange
        self.__szr_main = wx.BoxSizer(wx.VERTICAL)
        self.__szr_main.Add(self.__soap_editor, 1, wx.EXPAND)
        self.SetSizerAndFit(self.__szr_main)
Example #9
0
 def __init__(self, *args, **kwargs):
     wx.Panel.__init__(self, *args, **kwargs)
     self.__do_layout()
     self.__pat = gmPerson.gmCurrentPatient()
     if not self.__register_events():
         raise gmExceptions.ConstructorError('cannot register interests')
Example #10
0
    def __init__(self,
                 parent,
                 id,
                 pos=wxDefaultPosition,
                 size=wxDefaultSize,
                 style=wx.TAB_TRAVERSAL):

        wx.Panel.__init__(self, parent, id, pos, size, style)

        # if we are not inside gnumed we won't get a definite answer on
        # who and where we are. in this case try to get config source
        # from main config file (see gmCfg on how the name of this file
        # is determined
        # this is necessary to enable stand alone use of the drug browser
        currworkplace = gmPraxis.gmCurrentPraxisBranch().active_workplace
        if currworkplace is None:
            # assume we are outside gnumed
            self.dbName = _cfg.get('DrugReferenceBrowser', 'drugDBname')
        else:
            self.dbName, match = gmCfgINI.getDBParam(
                currworkplace, option="DrugReferenceBrowser.drugDBName")

        if self.dbName is None:
            if __name__ == '__main__':
                title = _('Starting drug data browser')
                msg = _(
                    'Cannot start the drug data browser.\n\n'
                    'There is no drug database specified in the configuration.'
                )
                gmGuiHelpers.gm_show_error(msg, title)
            _log.Log(gmLog.lErr,
                     "No drug database specified. Aborting drug browser.")
            # FIXME: we shouldn't directly call Close() on the parent
            #			parent.Close()
            raise gmExceptions.ConstructorError("No drug database specified")

# initialize interface to drug database.
        # this will fail if backend or config files are not available
        try:
            self.mDrugView = gmDrugView.DrugView(self.dbName)
        except Exception:
            _log.LogException("Unhandled exception during DrugView API init.",
                              sys.exc_info(),
                              verbose=0)
            raise gmExceptions.ConstructorError(
                "Couldn't initialize DrugView API")
#			return None

        self.mode = MODE_PRODUCT
        self.previousMode = MODE_PRODUCT
        self.printer = wx.HtmlEasyPrinting(
        )  #printer object to print html page
        self.mId = None
        self.drugProductInfo = None
        self.__mListCtrlItems = {
        }  # array holding data on every row in the list

        #-------------------------------------------------------------
        # These things build the physical window that you see when
        # the program boots. They each refer to a subroutine that
        # is listed below by the same name eg def Menus_Create(self)
        #-------------------------------------------------------------
        self.GuiElements_Init()  # add main gui elements
        self.inDisplay_PI = 0  # first we display a drug list, not product info
        self.GetDrugIssue()  # ?

        #--------------------------------------------------------------
        # handler declarations for DrugDisplay
        # note handlers for menu in Menus_Create()
        #--------------------------------------------------------------
        wx.EVT_BUTTON(self, ID_BUTTON_PRINT, self.OnPrint)
        wx.EVT_BUTTON(self, ID_BUTTON_DISPLAY, self.OnDisplay)
        wx.EVT_BUTTON(self, ID_BUTTON_PRESCRIBE, self.OnPrescribe)
        wx.EVT_LISTBOX_DCLICK(self, ID_LISTBOX_JUMPTO, self.OnJumpToDblClick)
        wx.EVT_LISTBOX(self, ID_LISTBOX_JUMPTO, self.OnJumpToSelected)
        wx.EVT_LIST_ITEM_ACTIVATED(self, ID_LISTCTRL_DRUGCHOICE,
                                   self.OnDrugChoiceDblClick)
        wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYINDICATION,
                           self.OnSearchByIndication)
        wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYGENERIC,
                           self.OnSearchByGeneric)
        wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYPRODUCT,
                           self.OnSearchByProduct)
        wx.EVT_RADIOBUTTON(self, ID_RADIOBUTTON_BYANY, self.OnSearchByAny)
        wx.EVT_TEXT(self, ID_COMBO_PRODUCT, self.OnProductKeyPressed)
        wx.EVT_COMBOBOX(self, ID_COMBO_PRODUCT, self.OnProductSelected)
        wx.EVT_BUTTON(self, wxID_OK, self.OnOk)
        wx.EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
        wx.EVT_BUTTON(self, ID_BUTTON_BOOKMARK, self.OnBookmark)