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

Source Code for Module Gnumed.business.gmProviderInbox

  1  # -*- coding: latin-1 -*- 
  2  """GNUmed provider inbox middleware. 
  3   
  4  This should eventually end up in a class cPractice. 
  5  """ 
  6  #============================================================ 
  7  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/business/gmProviderInbox.py,v $ 
  8  # $Id: gmProviderInbox.py,v 1.14 2009-12-01 21:48:42 ncq Exp $ 
  9  __license__ = "GPL" 
 10  __version__ = "$Revision: 1.14 $" 
 11  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>" 
 12   
 13   
 14  import sys 
 15   
 16   
 17  if __name__ == '__main__': 
 18          sys.path.insert(0, '../../') 
 19  from Gnumed.pycommon import gmPG2, gmBusinessDBObject 
 20   
 21  #============================================================ 
22 -class cInboxMessage(gmBusinessDBObject.cBusinessDBObject):
23 24 _cmd_fetch_payload = u"select * from dem.v_message_inbox where pk_message_inbox = %s" 25 26 _cmds_store_payload = [ 27 ] 28 29 u"""update clin.test_result set 30 clin_when = %(clin_when)s, 31 narrative = nullif(trim(%(comment)s), ''), 32 val_num = %(val_num)s, 33 val_alpha = nullif(trim(%(val_alpha)s), ''), 34 val_unit = nullif(trim(%(val_unit)s), ''), 35 val_normal_min = %(val_normal_min)s, 36 val_normal_max = %(val_normal_max)s, 37 val_normal_range = nullif(trim(%(val_normal_range)s), ''), 38 val_target_min = %(val_target_min)s, 39 val_target_max = %(val_target_max)s, 40 val_target_range = nullif(trim(%(val_target_range)s), ''), 41 abnormality_indicator = nullif(trim(%(abnormality_indicator)s), ''), 42 norm_ref_group = nullif(trim(%(norm_ref_group)s), ''), 43 note_test_org = nullif(trim(%(note_test_org)s), ''), 44 material = nullif(trim(%(material)s), ''), 45 material_detail = nullif(trim(%(material_detail)s), ''), 46 fk_intended_reviewer = %(pk_intended_reviewer)s, 47 fk_encounter = %(pk_encounter)s, 48 fk_episode = %(pk_episode)s, 49 fk_type = %(pk_test_type)s 50 where 51 pk = %(pk_test_result)s and 52 xmin = %(xmin_test_result)s""", 53 u"""select xmin_test_result from clin.v_test_results where pk_test_result = %(pk_test_result)s""" 54 55 _updatable_fields = [ 56 u'pk_staff', 57 u'pk_patient', 58 u'pk_type', 59 u'comment', 60 # u'pk_context', 61 u'data', 62 u'importance' 63 ]
64 #------------------------------------------------------------
65 -def get_inbox_messages(pk_staff=None, pk_patient=None, include_without_provider=False):
66 67 args = {} 68 where_parts = [] 69 70 if pk_staff is not None: 71 if include_without_provider: 72 where_parts.append(u'pk_staff in (%(staff)s, NULL)') 73 else: 74 where_parts.append(u'pk_staff = %(staff)s') 75 args['staff'] = pk_staff 76 77 if pk_patient is not None: 78 where_parts.append(u'pk_patient = %(pat)s') 79 args['pat'] = pk_patient 80 81 cmd = u""" 82 SELECT * 83 FROM dem.v_message_inbox 84 WHERE %s 85 ORDER BY importance desc, received_when desc""" % u' AND '.join(where_parts) 86 87 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': args}], get_col_idx = True) 88 return [ cInboxMessage(row = {'pk_field': 'pk_message_inbox', 'idx': idx, 'data': r}) for r in rows ]
89 #------------------------------------------------------------
90 -def delete_inbox_message(pk=None):
91 gmPG2.run_rw_queries(queries = [{'cmd': u"delete from dem.message_inbox where pk = %s", 'args': [pk]}]) 92 return True
93 #============================================================
94 -class cProviderInbox:
95 - def __init__(self, provider_id=None):
96 if provider_id is None: 97 from Gnumed.business import gmPerson 98 self.__provider_id = gmPerson.gmCurrentProvider()['pk_staff'] 99 else: 100 self.__provider_id = provider_id
101 #--------------------------------------------------------
102 - def _get_messages(self):
103 return get_inbox_messages(pk_staff = self.__provider_id)
104
105 - def _set_messages(self, messages):
106 return
107 108 messages = property(_get_messages, _set_messages) 109 #--------------------------------------------------------
110 - def delete_message(self, pk=None):
111 return delete_inbox_message(pk = pk)
112 #============================================================ 113 if __name__ == '__main__': 114 115 from Gnumed.pycommon import gmI18N 116 from Gnumed.business import gmPerson 117 118 gmI18N.activate_locale() 119 gmI18N.install_domain() 120 121 #---------------------------------------
122 - def test_inbox():
123 gmPerson.gmCurrentProvider(provider = gmPerson.cStaff()) 124 inbox = cProviderInbox() 125 for msg in inbox.messages: 126 print msg
127 #---------------------------------------
128 - def test_msg():
129 msg = cInboxMessage(aPK_obj = 1) 130 print msg
131 #--------------------------------------- 132 if (len(sys.argv) > 1) and (sys.argv[1] == 'test'): 133 test_inbox() 134 #test_msg() 135 136 #============================================================ 137 # $Log: gmProviderInbox.py,v $ 138 # Revision 1.14 2009-12-01 21:48:42 ncq 139 # - fix typo 140 # 141 # Revision 1.13 2009/11/30 22:24:36 ncq 142 # - add order by 143 # 144 # Revision 1.12 2009/08/24 20:03:59 ncq 145 # - proper cInboxMessage and use it 146 # 147 # Revision 1.11 2008/09/04 12:52:51 ncq 148 # - load received_when 149 # 150 # Revision 1.10 2007/10/30 12:47:53 ncq 151 # - fix test suite 152 # - make messages a property on inbox 153 # 154 # Revision 1.9 2007/03/01 13:51:13 ncq 155 # - remove call to _log 156 # 157 # Revision 1.8 2006/10/08 15:10:01 ncq 158 # - convert to gmPG2 159 # - return all the fields needed for inbox on error 160 # 161 # Revision 1.7 2006/05/20 18:30:09 ncq 162 # - cleanup 163 # 164 # Revision 1.6 2006/05/16 08:20:28 ncq 165 # - remove field duplication 166 # 167 # Revision 1.5 2006/05/15 14:38:43 ncq 168 # - include message PK in load list 169 # - add delete_message() 170 # 171 # Revision 1.4 2006/05/12 13:53:34 ncq 172 # - missing () 173 # 174 # Revision 1.3 2006/05/12 13:48:27 ncq 175 # - properly import gmPerson 176 # 177 # Revision 1.2 2006/05/12 12:04:30 ncq 178 # - use gmCurrentProvider 179 # - load more fields from inbox for later use 180 # 181 # Revision 1.1 2006/01/22 18:10:21 ncq 182 # - class for provider inbox 183 # 184 # 185