From be88764f0d1b09a7989571f43b12aed7ec4b723c Mon Sep 17 00:00:00 2001
From: Luke Leighton <lkcl@lkcl.net>
Date: Tue, 14 Sep 2010 11:52:44 +0100
Subject: [PATCH 33/34] add patient selector dialog

---
 .../client/ProxiedWeb/gui/PatientSelectDialog.py   |   50 ++++++++++++++++++++
 .../client/ProxiedWeb/gui/PatientsearchPanel.py    |   14 ++++--
 .../client/ProxiedWeb/gui/public/gnumedweb.xml     |    3 +
 3 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 gnumed/gnumed/client/ProxiedWeb/gui/PatientSelectDialog.py

diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/PatientSelectDialog.py b/gnumed/gnumed/client/ProxiedWeb/gui/PatientSelectDialog.py
new file mode 100644
index 0000000..27ce755
--- /dev/null
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/PatientSelectDialog.py
@@ -0,0 +1,50 @@
+from pyjamas.builder.Builder import Builder, HTTPUILoader
+import GMWevents
+
+#======================================================
+class cPatientSelector: 
+    """ Patient Selector.
+        
+    """
+    def __init__(self, patients):
+        self.ps = None
+        self.patients = patients
+        HTTPUILoader(self).load("gnumedweb.xml") # calls onUILoaded when done
+
+    #--------------------------------------------------
+    def onUILoaded(self, text):
+        self.b = Builder(text)
+        self.ps = self.b.createInstance("PatientSelect", self)
+        self.fill_grid()
+        self.ps.centerBox()
+        self.ps.show()
+
+    #--------------------------------------------------
+    def getPanel(self):
+        return self.ps
+
+    #--------------------------------------------------
+    def fill_grid(self):
+        grid = self.ps.vp.sp.grid
+        grid.resize(1+len(self.patients), 3)
+        for (row, patient) in enumerate(self.patients):
+            grid.setHTML(row+1, 0, patient.description)
+            grid.setHTML(row+1, 1, patient.formatted_dob)
+            grid.setHTML(row+1, 2, patient.xmin_identity)
+                
+    #--------------------------------------------------
+    def onPatientCellClicked(self, sender, row, col):
+        if row == 0:
+            return
+        patient = self.patients[row-1]
+        GMWevents.events.onPatientSelectedEvent(self, patient)
+        self.ps.hide()
+
+    #--------------------------------------------------
+    def onPatientSelectOk(self, sender):
+        self.ps.hide()
+
+    #--------------------------------------------------
+    def onPatientSelectCancel(self, sender):
+        self.ps.hide()
+
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py
index 1291959..e297389 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py
@@ -8,6 +8,8 @@ from pyjamas.ui.Label import Label
 from pyjamas.ui.Button import Button
 
 from WebguiHelpers import cSimplePopup
+from PatientSelectDialog import cPatientSelector
+
 
 import Remote
 import GMWevents
@@ -15,6 +17,7 @@ import GMWevents
 #======================================================
 class cPatientsearchPanel(HorizontalPanel):
     def __init__(self, **kwargs):
+        GMWevents.events.addPatientSelectedListener(self)
         HorizontalPanel.__init__(self, **kwargs)
 
         self.patientphoto = Image("images/empty-face-in-bust.png")
@@ -42,17 +45,20 @@ class cPatientsearchPanel(HorizontalPanel):
         method = request_info.method
         if method == 'search_patient':
             if isinstance(response, list):
-                # TODO: fire up selection dialog
                 GMWevents.events.onPatientSelectedEvent(self, None) 
+                selector = cPatientSelector(response)
                 return
 
-            self.searchbox.setText(response.description)
-
-            print dir(response)
             # notify listeners of patient details
             GMWevents.events.onPatientSelectedEvent(self, response)
 
     #--------------------------------------------------
+    def onPatientSelected(self, sender, patient):
+        if patient is None:
+            return
+        self.searchbox.setText(patient.description)
+
+    #--------------------------------------------------
     def onRemoteError(self, code, errobj, request_info):
         # onRemoteError gets the HTTP error code or 0 and
         # errobj is an jsonrpc 2.0 error dict:
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml b/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml
index d2ffbf4..4ed6d83 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml
@@ -445,6 +445,9 @@
 								<properties name="common">
 									<property name="name" value="grid" />
 								</properties>
+								<properties name="events">
+									<property name="onCellClicked" value="onPatientCellClicked" />
+								</properties>
 								<components>
 									<component id="None" index="(0, 0)">
 									</component>
-- 
1.7.1

