Gnumed.business.gmDataMining

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

# Source Code for Module Gnumed.business.gmDataMining

     1  """GNUmed data mining middleware."""
     2  #============================================================
     3  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/business/gmDataMining.py,v $
     4  # $Id: gmDataMining.py,v 1.3 2008-01-05 23:24:29 ncq Exp $
     5  __license__ = "GPL"
     6  __version__ = "$Revision: 1.3 $"
     7  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
     8
     9
    10  import sys
    11
    12
    13  if __name__ == '__main__':
    14          sys.path.insert(0, '../../')
    15  from Gnumed.pycommon import gmPG2
    16
    17
    18  #============================================================
    19 -def report_exists(name=None):
    20          rows, idx = gmPG2.run_ro_queries(queries = [{
    21                  'cmd': u'select exists(select 1 from cfg.report_query where label=%(name)s)',
    22                  'args': {'name': name}
    23          }])
    24          return rows[0][0]
    25  #--------------------------------------------------------
    26 -def save_report_definition(name=None, query=None, overwrite=False):
    27          if not overwrite:
    28                  if report_exists(name=name):
    29                          return False
    30
    31          queries = [
    32                  {'cmd': u'delete from cfg.report_query where label=%(name)s', 'args': {'name': name}},
    33                  {'cmd': u'insert into cfg.report_query (label, cmd) values (%(name)s, %(query)s)',
    34                   'args': {'name': name, 'query': query}}
    35          ]
    36          rows, idx = gmPG2.run_rw_queries(queries=queries)
    37          return True
    38  #--------------------------------------------------------
    39 -def delete_report_definition(name=None):
    40          queries = [{
    41                  'cmd': u'delete from cfg.report_query where label=%(name)s',
    42                  'args': {'name': name}
    43          }]
    44          rows, idx = gmPG2.run_rw_queries(queries=queries)
    45          return True
    46  #============================================================
    47  if __name__ == '__main__':
    48
    49          if len(sys.argv) > 1 and sys.argv[1] == 'test':
    50                  test_report = u'test suite report'
    51                  test_query = u'select 1 as test_suite_report_result'
    52
    53                  print "delete (should work):", delete_report_definition(name = test_report)
    54                  print "check (should return False):", report_exists(name = test_report)
    55                  print "save (should work):", save_report_definition(name = test_report, query = test_query)
    56                  print "save (should fail):", save_report_definition(name = test_report, query = test_query, overwrite = False)
    57                  print "save (should work):", save_report_definition(name = test_report, query = test_query, overwrite = True)
    58                  print "delete (should work):", delete_report_definition(name = test_report)
    59                  print "check (should return False):", report_exists(name = test_report)
    60  #============================================================
    61