From 131450b962fed4ce6f127acaf8177e7ae0d29f5e Mon Sep 17 00:00:00 2001
From: Luke Leighton <lkcl@lkcl.net>
Date: Mon, 13 Sep 2010 13:37:30 +0100
Subject: [PATCH 17/34] fixup get_provider_inbox_data server-side

---
 gnumed/gnumed/client/ProxiedWeb/gmWebGuiServer.py  |   16 ++++++++---
 gnumed/gnumed/client/ProxiedWeb/gui/Remote.py      |    1 +
 gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py   |   10 +++---
 .../gnumed/client/ProxiedWeb/gui/jsonobjproxy.py   |    3 ++
 gnumed/gnumed/client/testing/testjsonrpc.py        |   28 +++++++++++++++++---
 5 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/gnumed/gnumed/client/ProxiedWeb/gmWebGuiServer.py b/gnumed/gnumed/client/ProxiedWeb/gmWebGuiServer.py
index ff948b4..14f3fd6 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gmWebGuiServer.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gmWebGuiServer.py
@@ -8,17 +8,21 @@ __author__  = "S. Hilbert <Sebastian.Hilbert@gmx.net>"
 __license__ = "GPL (details at http://www.gnu.org)"
 
 # stdlib
-import re, sys, time, os, cPickle, zlib, locale, os.path, datetime as pyDT, webbrowser, shutil, logging, urllib2
+import re, sys, time, os, cPickle, zlib, locale, os.path
+import datetime as pyDT, webbrowser, shutil, logging, urllib2
 
 # json-rpc
 from jsonserver import SimpleForkingJSONRPCServer
 
 # GNUmed libs
 from Gnumed.pycommon import gmI18N, gmTools, gmDateTime, gmHooks
-from Gnumed.pycommon import gmLoginInfo, gmBackendListener, gmTools, gmCfg2, gmI18N, gmDispatcher, gmBusinessDBObject
+from Gnumed.pycommon import gmLoginInfo, gmBackendListener, gmTools, gmCfg2
+from Gnumed.pycommon import gmCfg2, gmI18N, gmDispatcher, gmBusinessDBObject
 from Gnumed.pycommon.gmBusinessDBObject import jsonclasshintify
 from Gnumed.pycommon import gmPG2
 from Gnumed.business import gmDocuments
+from Gnumed.business import gmPerson
+from Gnumed.business import gmProviderInbox
 
 #try:
 #   _('dummy-no-need-to-translate-but-make-epydoc-happy')
@@ -338,6 +342,7 @@ class HTTPServer(SimpleForkingJSONRPCServer):
         self.register_function(self.echo)
         self.register_function(self.login)
         self.register_function(self.search_patient)
+        self.register_function(self.get_provider_inbox_data)
         self.register_function(self.get_doc_types)
         self.register_function(self.get_documents)
         self.register_function(self.get_schema_version)
@@ -436,10 +441,11 @@ class HTTPServer(SimpleForkingJSONRPCServer):
         return None
 
     def get_provider_inbox_data(self):
-        self.provider = gmPerson.gmCurrentProvider()
-        self.__msgs = self.provider.inbox.messages
+        self.provider = gmPerson.gmCurrentProvider(provider=gmPerson.cStaff())
+        inbox = gmProviderInbox.cProviderInbox()
+        self.__msgs = inbox.messages
         """convert from objects to dict - maybe that works """
-        return inbox_messages
+        return jsonclasshintify(inbox.messages)
 
     def get_schema_version(self):
         return gmPG2.get_schema_version()
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/Remote.py b/gnumed/gnumed/client/ProxiedWeb/gui/Remote.py
index 1fe5b78..174fd1f 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/Remote.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/Remote.py
@@ -10,6 +10,7 @@ class EchoServicePython(JSONProxy):
                 "echo", "get_doc_types",
                 "get_schema_version",
                 "get_documents",
+                "get_provider_inbox_data",
                 "doSomething",
                 "search_patient"])
 
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py
index 9b22094..4b255ad 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py
@@ -32,10 +32,10 @@ class cTestPanel(VerticalPanel):
         self.METHOD_ECHO = "Echo"
         self.METHOD_DOCTYPES = "get doc types"
         self.METHOD_UPPERCASE = "get schema"
-        self.METHOD_LOWERCASE = "doSomething"
+        self.METHOD_GETINBOX = "get inbox"
         self.METHOD_GETDOCS = "get documents"
         self.methods = [self.METHOD_ECHO, self.METHOD_DOCTYPES, 
-                     self.METHOD_UPPERCASE, self.METHOD_LOWERCASE, 
+                     self.METHOD_UPPERCASE, self.METHOD_GETINBOX, 
                         self.METHOD_GETDOCS]
 
         self.method_list = ListBox()
@@ -79,8 +79,8 @@ class cTestPanel(VerticalPanel):
                 id = Remote.svc.get_doc_types(self)
             elif method == self.METHOD_UPPERCASE:
                 id = Remote.svc.get_schema_version(self)
-            elif method == self.METHOD_LOWERCASE:
-                id = Remote.svc.doSomething(self)
+            elif method == self.METHOD_GETINBOX:
+                id = Remote.svc.get_provider_inbox_data(self)
             elif method == self.METHOD_GETDOCS:
                 key = int(self.dockey.getText()) # TODO: check it!
                 id = Remote.svc.get_documents(key, self)
@@ -118,7 +118,7 @@ class cTestPanel(VerticalPanel):
                                 (code, message))
         else:
             code = errobj['code']
-            if message['message'] == 'Cannot request login parameters.':
+            if message == 'Cannot request login parameters.':
                 self.status.setText("You need to log in first")
             else:
                 self.status.setText("JSONRPC Error %s: %s" %
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/jsonobjproxy.py b/gnumed/gnumed/client/ProxiedWeb/gui/jsonobjproxy.py
index 941621e..6a61041 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/jsonobjproxy.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/jsonobjproxy.py
@@ -11,6 +11,9 @@ class cDocumentType(Proxy):
 class cMedDoc(Proxy):
     pass
 
+class cInboxMessage(Proxy):
+    pass
+
 class cMedDocPart(Proxy):
     pass
 
diff --git a/gnumed/gnumed/client/testing/testjsonrpc.py b/gnumed/gnumed/client/testing/testjsonrpc.py
index d4c0c61..09b0f4a 100644
--- a/gnumed/gnumed/client/testing/testjsonrpc.py
+++ b/gnumed/gnumed/client/testing/testjsonrpc.py
@@ -21,7 +21,7 @@ class TestJsonServer(unittest.TestCase):
         print
 
 
-    def test_login(self):
+    def notest_login(self):
         session = proxy.Session(username="", password="")
         s = proxy.ServerProxy("http://127.0.0.1:8080/JSON", 
                               session=session, send_id=True)
@@ -58,14 +58,34 @@ class TestJsonServer(unittest.TestCase):
         print "3", reply
         print
 
-        reply = s3.get_doc_types()
-        print "3", reply
-        print
+        try:
+            reply = s3.get_doc_types()
+            print "3", reply
+            print
+        except:
+            print "unexpected failure"
 
         reply = s2.get_doc_types()
         print "2", reply
         print
 
+    def test_inbox(self):
+        session = proxy.Session(username="", password="")
+        s = proxy.ServerProxy("http://127.0.0.1:8080/JSON", 
+                              session=session, send_id=True)
+
+        reply = s.login("any-doc", "any-doc")
+        print "login", reply
+
+        reply = s.get_schema_version()
+        print "schema", reply
+
+        reply = s.get_doc_types()
+        print "doctypes", reply
+
+        reply = s.get_provider_inbox_data()
+        print reply
+        
 if __name__=="__main__":
     unittest.main()
 
-- 
1.7.1

