Gnumed.importers.gmSMSImporter

Package Gnumed :: Package importers :: Module gmSMSImporter |
[frames] | no frames]

# Source Code for Module Gnumed.importers.gmSMSImporter

      1
      2  import sys, datetime as dt
      3
      4
      5  if __name__ == '__main__':
      6          sys.path.insert(0, '../../')
      7  from Gnumed.pycommon import gmPG2, gmI18N, gmDateTime
      8  from Gnumed.business import gmPerson
      9
     10
     11  # define some defaults
     12  external_id_type = 'SMS-Waage'
     13  idx_date = 1
     14  idx_gsm = 2
     15  idx_sms = 3
     16  soap_cat = 'o'
     17  weight_template = 'aktuelles Gewicht (%s)::%s'
     18  #==============================================
     19 -class cLogin:
     20          pass
     21
     22 -def usage():
     23          print "use like this:"
     24          print ""
     25          print " gmSMSImporter.py <date> <gsm> <weight>"
     26          print " <weight> must be: <patient id>:::<weight value>"
     27          print ""
     28          print " current command line:", sys.argv
     29
     30 -def run_importer():
     31
     32          # map data from commandline
     33          try:
     34                  date = sys.argv[idx_date]
     35                  gsm = sys.argv[idx_gsm]
     36                  sms = sys.argv[idx_sms]
     37                  pk_patient, weight = sms.split(':::')
     38          except:
     39                  return False
     40
     41          # find patient by gsm
     42  #       cmd1 = u"select dem.add_external_id_type(%(desc)s, %(org)s)"
     43  #       args1 = {'desc': external_id_type, 'org': u'gmSMSImporter.py'}
     44  #       cmd2 = u'select pk from dem.enum_ext_id_types where name = %(desc)s'
     45  #       rows, idx = gmPG2.run_rw_queries (
     46  #               queries = [
     47  #                       {'cmd': cmd1, 'args': args1},
     48  #                       {'cmd': cmd2, 'args': args1}
     49  #               ],
     50  #               return_data = True
     51  #       )
     52  #       ext_id_pk = rows[0][0]
     53
     54  #       cmd = u"""
     55  #select li2id.id_identity
     56  #from dem.lnk_identity2ext_id li2id
     57  #where
     58  #       li2id.external_id = %(id)s and
     59  #       fk_origin = %(src)s"""
     60  #       args = {'id': gsm, 'src': ext_id_pk}
     61
     62  #       rows, idx = gmPG2.run_ro_queries (
     63  #               queries = [{'cmd': cmd, 'args': args}],
     64  #               return_data = True
     65  #       )
     66  #       if len(rows) == 0:
     67  #               print "patient with GSM [%s] not found" % gsm
     68  #               return False
     69  #       pk_patient = rows[0][0]
     70
     71          gmPerson.set_active_patient(patient = gmPerson.cPerson(aPK_obj = pk_patient))
     72
     73          # ensure structure of EMR
     74          curr_pat = gmPerson.gmCurrentPatient()
     75          emr = curr_pat.emr
     76          epi = emr.add_episode(episode_name = 'Gewichtsmonitoring', is_open = False)
     77
     78          # and import our stuff
     79          narr = emr.add_clin_narrative (
     80                  note = weight_template % (dt.datetime.now().strftime('%X'), weight),
     81                  soap_cat = soap_cat,
     82                  episode = epi
     83          )
     84
     85          return True
     86  #==============================================
     87  if __name__ == '__main__':
     88
     89          gmI18N.activate_locale()
     90          gmI18N.install_domain(domain = 'gnumed')
     91          gmDateTime.init()
     92
     93          login = cLogin()
     94          login.database = 'gnumed_v9'
     95          login.host = 'publicdb.gnumed.de'
     96          login.port = 5432
     97          login.user = 'any-doc'
     98          login.password = 'any-doc'
     99          gmPG2.set_default_login(login = login)
    100
    101          if not run_importer():
    102                  usage()
    103                  sys.exit()
    104