Package Gnumed :: Package business :: Module gmSurgery |
[frames] | no frames]

# Source Code for Module Gnumed.business.gmSurgery

      1  """GNUmed Surgery related middleware."""
      2  #============================================================
      3  __license__ = "GPL"
      4  __version__ = "$Revision: 1.14 $"
      5  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
      6
      7
      8  import sys, os
      9
     10
     11  if __name__ == '__main__':
     12          sys.path.insert(0, '../../')
     13  from Gnumed.pycommon import gmPG2, gmTools, gmBorg, gmCfg2
     14
     15  _cfg = gmCfg2.gmCfgData()
     16  #============================================================
     17 -def delete_workplace(workplace=None, delete_config=False, conn=None):
     18
     19          args = {'wp': workplace}
     20
     21          # delete workplace itself (plugin load list, that is)
     22          queries = [
     23                  {'cmd': u"""
     24  delete from cfg.cfg_item
     25  where
     26          fk_template = (
     27                  select pk
     28                  from cfg.cfg_template
     29                  where name = 'horstspace.notebook.plugin_load_order'
     30          )
     31                  and
     32          workplace = %(wp)s""",
     33                  'args': args
     34                  }
     35          ]
     36
     37          # delete other config items associated with this workplace
     38          if delete_config:
     39                  queries.append ({
     40                          'cmd': u"""
     41  delete from cfg.cfg_item
     42  where
     43          workplace = %(wp)s""",
     44                          'args': args
     45                  })
     46
     47          gmPG2.run_rw_queries(link_obj = conn, queries = queries, end_tx = True)
     48  #============================================================
     49 -class gmCurrentPractice(gmBorg.cBorg):
     50
     51 -        def __init__(self):
     52                  try:
     53                          self.already_inited
     54                          return
     55                  except AttributeError:
     56                          pass
     57
     58                  self.__helpdesk = None
     59                  self.__active_workplace = None
     60
     61                  self.already_inited = True
     62          #--------------------------------------------------------
     63          # waiting list handling
     64          #--------------------------------------------------------
     65 -        def remove_from_waiting_list(self, pk=None):
     66                  cmd = u'delete from clin.waiting_list where pk = %(pk)s'
     67                  args = {'pk': pk}
     68                  gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
     69          #--------------------------------------------------------
     70 -        def update_in_waiting_list(self, pk = None, urgency = 0, comment = None, zone = None):
     71                  cmd = u"""
     72  update clin.waiting_list
     73  set
     74          urgency = %(urg)s,
     75          comment = %(cmt)s,
     76          area = %(zone)s
     77  where
     78          pk = %(pk)s"""
     79                  args = {
     80                          'pk': pk,
     81                          'urg': urgency,
     82                          'cmt': gmTools.none_if(comment, u''),
     83                          'zone': gmTools.none_if(zone, u'')
     84                  }
     85
     86                  gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
     87          #--------------------------------------------------------
     88 -        def raise_in_waiting_list(self, current_position=None):
     89                  if current_position == 1:
     90                          return
     91
     92                  cmd = u'select clin.move_waiting_list_entry(%(pos)s, (%(pos)s - 1))'
     93                  args = {'pos': current_position}
     94
     95                  gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
     96          #--------------------------------------------------------
     97 -        def lower_in_waiting_list(self, current_position=None):
     98                  cmd = u'select clin.move_waiting_list_entry(%(pos)s, (%(pos)s+1))'
     99                  args = {'pos': current_position}
    100
    101                  gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
    102          #--------------------------------------------------------
    103          # properties
    104          #--------------------------------------------------------
    105 -        def _get_waiting_list_patients(self):
    106                  cmd = u"""
    107                          SELECT * FROM clin.v_waiting_list
    108                          ORDER BY
    109                                  list_position
    110                  """
    111                  rows, idx = gmPG2.run_ro_queries (
    112                          queries = [{'cmd': cmd}],
    113                          get_col_idx = False
    114                  )
    115                  return rows
    116
    117          waiting_list_patients = property (_get_waiting_list_patients, lambda x:x)
    118          #--------------------------------------------------------
    119 -        def _set_helpdesk(self, helpdesk):
    120                  return
    121
    122 -        def _get_helpdesk(self):
    123
    124                  if self.__helpdesk is not None:
    125                          return self.__helpdesk
    126
    127                  self.__helpdesk = gmTools.coalesce (
    128                          _cfg.get (
    129                                  group = u'workplace',
    130                                  option = u'help desk',
    131                                  source_order = [
    132                                          ('explicit', 'return'),
    133                                          ('workbase', 'return'),
    134                                          ('local', 'return'),
    135                                          ('user', 'return'),
    136                                          ('system', 'return')
    137                                  ]
    138                          ),
    139                          u'http://wiki.gnumed.de'
    140                  )
    141
    142                  return self.__helpdesk
    143
    144          helpdesk = property(_get_helpdesk, _set_helpdesk)
    145          #--------------------------------------------------------
    146 -        def _get_db_logon_banner(self):
    147                  rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'select _(message) from cfg.db_logon_banner'}])
    148                  if len(rows) == 0:
    149                          return u''
    150                  return gmTools.coalesce(rows[0][0], u'').strip()
    151
    152 -        def _set_db_logon_banner(self, banner):
    153                  queries = [
    154                          {'cmd': u'delete from cfg.db_logon_banner'}
    155                  ]
    156                  if banner.strip() != u'':
    157                          queries.append ({
    158                                  'cmd': u'insert into cfg.db_logon_banner (message) values (%(msg)s)',
    159                                  'args': {'msg': banner.strip()}
    160                          })
    161                  rows, idx = gmPG2.run_rw_queries(queries = queries, end_tx = True)
    162
    163          db_logon_banner = property(_get_db_logon_banner, _set_db_logon_banner)
    164          #--------------------------------------------------------
    165 -        def _set_workplace(self, workplace):
    166                  # maybe later allow switching workplaces on the fly
    167                  return True
    168
    169 -        def _get_workplace(self):
    170                  """Return the current workplace (client profile) definition.
    171
    172                  The first occurrence counts.
    173                  """
    174                  if self.__active_workplace is not None:
    175                          return self.__active_workplace
    176
    177                  self.__active_workplace = gmTools.coalesce (
    178                          _cfg.get (
    179                                  group = u'workplace',
    180                                  option = u'name',
    181                                  source_order = [
    182                                          ('explicit', 'return'),
    183                                          ('workbase', 'return'),
    184                                          ('local', 'return'),
    185                                          ('user', 'return'),
    186                                          ('system', 'return'),
    187                                  ]
    188                          ),
    189                          u'Local Default'
    190                  )
    191
    192                  return self.__active_workplace
    193
    194          active_workplace = property(_get_workplace, _set_workplace)
    195          #--------------------------------------------------------
    196 -        def _set_workplaces(self, val):
    197                  pass
    198
    199 -        def _get_workplaces(self):
    200                  rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u'select distinct workplace from cfg.cfg_item'}])
    201                  return [ r[0] for r in rows ]
    202
    203          workplaces = property(_get_workplaces, _set_workplaces)
    204          #--------------------------------------------------------
    205 -        def _get_user_email(self):
    206                  # FIXME: get this from the current users staff record in the database
    207                  return _cfg.get (
    208                          group = u'preferences',
    209                          option = u'user email',
    210                          source_order = [
    211                                  ('explicit', 'return'),
    212                                  ('user', 'return'),
    213                                  ('local', 'return'),
    214                                  ('workbase', 'return'),
    215                                  ('system', 'return')
    216                          ]
    217                  )
    218
    219 -        def _set_user_email(self, val):
    220                  prefs_file = _cfg.get(option = 'user_preferences_file')
    221                  gmCfg2.set_option_in_INI_file (
    222                          filename = prefs_file,
    223                          group = u'preferences',
    224                          option = u'user email',
    225                          value = val
    226                  )
    227                  _cfg.reload_file_source(file = prefs_file)
    228
    229          user_email = property(_get_user_email, _set_user_email)
    230  #============================================================
    231  if __name__ == '__main__':
    232
    233 -        def run_tests():
    234                  prac = gmCurrentPractice()
    235  #               print "help desk:", prac.helpdesk
    236  #               print "active workplace:", prac.active_workplace
    237
    238                  old_banner = prac.db_logon_banner
    239                  test_banner = u'a test banner'
    240                  prac.db_logon_banner = test_banner
    241                  if prac.db_logon_banner != test_banner:
    242                          print 'Cannot set logon banner to', test_banner
    243                          return False
    244                  prac.db_logon_banner = u''
    245                  if prac.db_logon_banner != u'':
    246                          print 'Cannot set logon banner to ""'
    247                          return False
    248                  prac.db_logon_banner = old_banner
    249
    250                  return True
    251
    252          if len(sys.argv) > 1 and sys.argv[1] == 'test':
    253                  if not run_tests():
    254                          print "regression tests failed"
    255                  print "regression tests succeeded"
    256
    257  #============================================================
    258