From 336a76a21e6597f8fb39b22f1ba436ac98735bc7 Mon Sep 17 00:00:00 2001
From: Luke Leighton <lkcl@lkcl.net>
Date: Mon, 13 Sep 2010 18:23:52 +0100
Subject: [PATCH 27/34] add ProviderInboxPanel to patient summary

---
 .../client/ProxiedWeb/gui/PatientsummaryPanel.py   |   30 ++++++--------
 .../client/ProxiedWeb/gui/ProviderInboxPanel.py    |   43 +++++++++++++++-----
 2 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py
index a1c6557..9fdaf7d 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py
@@ -1,31 +1,27 @@
-from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.StackPanel import StackPanel
 from pyjamas.ui.HTML import HTML
 
-class cPatientsummaryPanel(SimplePanel):
-    def __init__(self):
-        SimplePanel.__init__(self)
+from ProviderInboxPanel import cProviderInboxPanel
 
-        stack = StackPanel(Width="100%", Height="300px")
+class cPatientsummaryPanel(StackPanel):
+    def __init__(self):
+        StackPanel.__init__(self, Width="100%", Height="300px")
 
-        stack.add(HTML('The quick<br>brown fox<br>jumps over the<br>lazy dog.'),
-                  "Inbox")
-        stack.add(HTML('The<br>early<br>bird<br>catches<br>the<br>worm.'),
+        self.add(cProviderInboxPanel(), "Inbox")
+        self.add(HTML('The<br>early<br>bird<br>catches<br>the<br>worm.'),
                   "Waiting list")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Demographic and identity")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Hospitalization (most recent known)")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Operation (most recent known)")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Allergies and intolerances (known)")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Medication, current (known)")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Medication, discontinued (known, past 120 days)")
-        stack.add(HTML('The smart money<br>is on the<br>black horse.'),
+        self.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Problem list")
  
-        self.add(stack)
-
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/ProviderInboxPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/ProviderInboxPanel.py
index 6359f43..4872679 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/ProviderInboxPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/ProviderInboxPanel.py
@@ -1,11 +1,14 @@
 from pyjamas.builder.Builder import Builder, HTTPUILoader
+from pyjamas.ui.SimplePanel import SimplePanel
 import GMWevents
 import Remote
 
 #======================================================
-class cProviderInboxPanel: 
-    def __init__(self):
+class cProviderInboxPanel(SimplePanel): 
+    def __init__(self, **kwargs):
+        SimplePanel.__init__(self, **kwargs)
         self.pp = None
+        self.messages = []
         self.active_patient_id = None
         self.TEXT_WAITING = "Waiting for response..."
         HTTPUILoader(self).load("gnumedweb.xml") # calls onUILoaded when done
@@ -13,24 +16,26 @@ class cProviderInboxPanel:
     def onUILoaded(self, text):
         self.b = Builder(text)
         self.pp = self.b.createInstance("ProviderInbox", self)
-        GMWevents.login.addLoginListener(self)
+        GMWevents.events.addPatientSelectedListener(self)
+        GMWevents.events.addLoginListener(self)
+        self.add(self.pp)
 
     def getPanel(self):
         return self.pp
 
     #--------------------------------------------------
-    def fill_grid(self, _messages):
+    def fill_grid(self):
         show_active_only = self.pp.hpShow.rdbActive.getChecked()
         if show_active_only and self.active_patient_id:
             messages = []
-            for item in _messages:
+            for item in self.messages:
                 if item.pk_patient == self.active_patient_id:
                     messages.append(item)
         else:
-            messages = _messages
+            messages = self.messages
                 
         grid = self.pp.grid
-        grid.resize(1, 1+len(messages))
+        grid.resize(1+len(messages), 5)
         for (row, item) in enumerate(messages):
             grid.setHTML(row+1, 1, str(item.received_when))
             grid.setHTML(row+1, 2, item.category)
@@ -38,9 +43,24 @@ class cProviderInboxPanel:
             grid.setHTML(row+1, 4, item.comment)
 
     #--------------------------------------------------
-    def onPatientSelected(self, patient_info):
-        self.active_patient_id = patient_info.
-        Remote.svc.get_provider_inbox_data(self)
+    def onAllMessagesSelected(self, sender):
+        print "all selected"
+        print self.pp.hpShow.rdbActive._clickListeners
+        self.fill_grid()
+
+    #--------------------------------------------------
+    def onPatientMessagesSelected(self, sender):
+        print "patient selected"
+        self.fill_grid()
+
+    #--------------------------------------------------
+    def onPatientSelected(self, sender, patient_info):
+        if patient_info is not None:
+            self.active_patient_id = patient_info.pk_identity
+        else:
+            self.active_patient_id = None
+        print "patient id", self.active_patient_id
+        self.fill_grid()
 
     #--------------------------------------------------
     def onLogin(self, sender, username, logged_in):
@@ -52,7 +72,8 @@ class cProviderInboxPanel:
         method = request_info.method
 
         if method == 'get_provider_inbox_data':
-            self.fill_grid(response)
+            self.messages = response
+            self.fill_grid()
 
     #--------------------------------------------------
     def onRemoteError(self, code, errobj, request_info):
-- 
1.7.1

