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: /cvsroot/gnumed/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_old(self):
103 cmd = u""" 104 select 105 importance, 106 l10n_category, 107 l10n_type, 108 comment, 109 category, 110 type, 111 pk_context, 112 data, 113 pk_message_inbox, 114 received_when, 115 pk_patient 116 from dem.v_message_inbox 117 where pk_staff = %s 118 order by importance desc, received_when desc""" 119 try: 120 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': [self.__provider_id]}]) 121 except: 122 return [[ 123 1, 124 _('error'), 125 _('error'), 126 _('unable to get provider inbox messages from database'), 127 'error', 128 'error', 129 None, 130 _('An error occurred while retrieving provider inbox messages from the database.'), 131 None, 132 None, 133 None 134 ]] 135 return rows
136 #--------------------------------------------------------
137 - def _get_messages(self):
138 return get_inbox_messages(pk_staff = self.__provider_id)
139
140 - def _set_messages(self, messages):
141 return
142 143 messages = property(_get_messages, _set_messages) 144 #--------------------------------------------------------
145 - def delete_message(self, pk=None):
146 return delete_inbox_message(pk = pk)
147 #============================================================ 148 if __name__ == '__main__': 149 150 from Gnumed.pycommon import gmI18N 151 from Gnumed.business import gmPerson 152 153 gmI18N.activate_locale() 154 gmI18N.install_domain() 155 156 #---------------------------------------
157 - def test_inbox():
158 gmPerson.gmCurrentProvider(provider = gmPerson.cStaff()) 159 inbox = cProviderInbox() 160 for msg in inbox.messages: 161 print msg
162 #---------------------------------------
163 - def test_msg():
164 msg = cInboxMessage(aPK_obj = 1) 165 print msg
166 #--------------------------------------- 167 if (len(sys.argv) > 1) and (sys.argv[1] == 'test'): 168 test_inbox() 169 #test_msg() 170 171 #============================================================ 172 # $Log: gmProviderInbox.py,v $ 173 # Revision 1.14 2009/12/01 21:48:42 ncq 174 # - fix typo 175 # 176 # Revision 1.13 2009/11/30 22:24:36 ncq 177 # - add order by 178 # 179 # Revision 1.12 2009/08/24 20:03:59 ncq 180 # - proper cInboxMessage and use it 181 # 182 # Revision 1.11 2008/09/04 12:52:51 ncq 183 # - load received_when 184 # 185 # Revision 1.10 2007/10/30 12:47:53 ncq 186 # - fix test suite 187 # - make messages a property on inbox 188 # 189 # Revision 1.9 2007/03/01 13:51:13 ncq 190 # - remove call to _log 191 # 192 # Revision 1.8 2006/10/08 15:10:01 ncq 193 # - convert to gmPG2 194 # - return all the fields needed for inbox on error 195 # 196 # Revision 1.7 2006/05/20 18:30:09 ncq 197 # - cleanup 198 # 199 # Revision 1.6 2006/05/16 08:20:28 ncq 200 # - remove field duplication 201 # 202 # Revision 1.5 2006/05/15 14:38:43 ncq 203 # - include message PK in load list 204 # - add delete_message() 205 # 206 # Revision 1.4 2006/05/12 13:53:34 ncq 207 # - missing () 208 # 209 # Revision 1.3 2006/05/12 13:48:27 ncq 210 # - properly import gmPerson 211 # 212 # Revision 1.2 2006/05/12 12:04:30 ncq 213 # - use gmCurrentProvider 214 # - load more fields from inbox for later use 215 # 216 # Revision 1.1 2006/01/22 18:10:21 ncq 217 # - class for provider inbox 218 # 219 # 220