[Mpuls-commits] r139 - in waska/trunk: . waskaweb/controllers waskaweb/lib waskaweb/model waskaweb/public/styles waskaweb/templates/casemanagement

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 8 15:24:27 CEST 2008


Author: torsten
Date: 2008-09-08 15:24:26 +0200 (Mon, 08 Sep 2008)
New Revision: 139

Modified:
   waska/trunk/ChangeLog.txt
   waska/trunk/waskaweb/controllers/case_overview.py
   waska/trunk/waskaweb/controllers/waska.py
   waska/trunk/waskaweb/lib/search.py
   waska/trunk/waskaweb/model/phases_factory.py
   waska/trunk/waskaweb/public/styles/all.css
   waska/trunk/waskaweb/templates/casemanagement/listbadcases.mako
Log:
Added more inconsistency checks


Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/ChangeLog.txt	2008-09-08 13:24:26 UTC (rev 139)
@@ -1,3 +1,16 @@
+2008-09-08	Torsten Irlaender  <torsten.irlaender at intevation.de>
+
+	Added more inconsistency checks
+
+	* model/phases_factory.py,
+	  controllers/case_overview.py,
+	  controllers/waska.py,
+	  lib/search.py,
+	  public/styles/all.css,
+	  templates/casemanagement/listbadcases.mako: Added inconsistency
+	  checks for missing fields in a particular phase. Furter refactored
+	  the listing a the inconsistent cases.
+
 2008-09-08  Sascha L. Teichmann <sascha.teichmann at intevation.de>
 
 	* waskaweb/model/navigation.py: add method findTreeItem().

Modified: waska/trunk/waskaweb/controllers/case_overview.py
===================================================================
--- waska/trunk/waskaweb/controllers/case_overview.py	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/waskaweb/controllers/case_overview.py	2008-09-08 13:24:26 UTC (rev 139)
@@ -40,11 +40,13 @@
 from waskaweb.lib.security         import checkRole
 from waskaweb.model.case           import CaseOverview, CaseBundle
 from waskaweb.model.user           import UserListObject, UserObject, UserGroupList
+from waskaweb.lib.search           import build_inconsistency_type_querys 
 from waskaweb.controllers.CaseBase import CasebaseController
 
 from waskaweb.lib.exportselection  import CasePartsSelection
 
 from datetime import datetime
+from threading import Lock
 
 log = logging.getLogger(__name__)
 
@@ -300,13 +302,14 @@
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
     def listBadCases(self):
         user = session.get('USER_AUTHORIZED')
-        c.type_1_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:1' % user.id)
-        c.type_2_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:2' % user.id)
-        c.type_3_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:3' % user.id)
-        c.type_4_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:4' % user.id)
-        c.type_5_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:5' % user.id)
-        c.type_6_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:6' % user.id)
-        c.type_7_list = CaseOverview().search('state:1;state:2;state:4;state:5;own:%s;inconsistency:7' % user.id)
+        c.inconsistency_types = {}
+        try:
+            for k,v in build_inconsistency_type_querys().iteritems():
+                s = 'state:1;state:2;state:4;state:5;own:%s;inconsistency:%s' % (user.id, k)
+                l = CaseOverview().search(s)
+                c.inconsistency_types[k] = l
+        except StandardError, err:
+            print err
         return render('/casemanagement/listbadcases.mako')
 
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))

Modified: waska/trunk/waskaweb/controllers/waska.py
===================================================================
--- waska/trunk/waskaweb/controllers/waska.py	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/waskaweb/controllers/waska.py	2008-09-08 13:24:26 UTC (rev 139)
@@ -86,7 +86,7 @@
             c.news = NewsList(user)
 
         #find out if there are cases with errors
-        search_str = "state:1;state:2;state:3;state:4;state:5;bad:1;bad:2;bad:3;bad:4;bad:5;bad:6;own:%s" % user.id
+        search_str = "state:1;state:2;state:3;state:4;state:5;bad:1;bad:2;bad:3;bad:4;bad:5;bad:6;bad:clearing_start;bad:clearing_ende;bad:beratung_start;bad:beratung_ende;bad:cm_start;bad:cm_ende;bad:nachbetreuung_start;bad:nachbetreuung_ende;own:%s" % user.id
         c.num_error_cases = len(CaseOverview().search(search_str))
         if c.num_error_cases > 0:
             session['hascaseerrors'] = True

Modified: waska/trunk/waskaweb/lib/search.py
===================================================================
--- waska/trunk/waskaweb/lib/search.py	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/waskaweb/lib/search.py	2008-09-08 13:24:26 UTC (rev 139)
@@ -31,7 +31,9 @@
 import sys
 import re
 from datetime import datetime
+from threading import Lock
 from waskaweb.lib.db import db
+from waskaweb.model.phases_factory import RequiredFields
 import psycopg2.extras
 from waskaweb.lib.base import session, g, h, config 
 
@@ -77,13 +79,8 @@
       AND %s
     ORDER BY %s %s"""
 
-INCONSISTENCY_TYPE_QUERY = {'1': 'm.erstgespraech is NULL', 
-                  '2': 'm.erstgespraech::timestamp > now()',
-                  '3': 'm.erstgespraech::timestamp > m.beendigung_5::timestamp',
-                  '4': 'm.beendigung_5::timestamp > now()',
-                  '5': '(m.art_beendigung <> -1 AND m.beendigung_5 is NULL)',
-                  '6': '(m.art_beendigung = -1 AND m.beendigung_5 is not NULL)',
-                  '7': '(m.phase = -1)'}
+INCONSISTENCY_LOCK = None
+INCONSISTENCY_TYPE_QUERY = None
 
 SEARCH_AGENCY_SQL = \
 """select count(m.id) as anzahl,
@@ -98,6 +95,25 @@
 group by fkz
 ORDER BY %s %s"""
 
+
+def build_inconsistency_type_querys():
+
+    querys = {'1': 'm.erstgespraech is NULL', 
+              '2': 'm.erstgespraech::timestamp > now()',
+              '3': 'm.erstgespraech::timestamp > m.beendigung_5::timestamp',
+              '4': 'm.beendigung_5::timestamp > now()',
+              '5': '(m.art_beendigung <> -1 AND m.beendigung_5 is NULL)',
+              '6': '(m.art_beendigung = -1 AND m.beendigung_5 is not NULL)',
+              '7': '(m.phase = -1)'}
+
+    #Now fetch more inconsistencys based on phases
+    rf = RequiredFields()
+    rf.extractRequiredFields(g.formedTree)
+    sql = rf.getSQLWhereClauses()
+    for s,q in sql:
+        querys[s] = q 
+    return querys
+
 class Search:
     def __init__(self):
         pass
@@ -124,7 +140,7 @@
                             if key == 'phase':
                                 phases.append(int(value))
                             if key in ['inconsistency', 'bad']:
-                                bad_types.append(int(value))
+                                bad_types.append(value)
                             else:
                                 options[key] = value
                     except ValueError:
@@ -219,6 +235,20 @@
 
         #Identify bad cases
         bad_query = []
+
+        global INCONSISTENCY_LOCK 
+        INCONSISTENCY_LOCK= Lock()
+        global INCONSISTENCY_TYPE_QUERY
+        INCONSISTENCY_LOCK.acquire()
+        try:
+            try:
+                if not INCONSISTENCY_TYPE_QUERY:
+                    INCONSISTENCY_TYPE_QUERY = build_inconsistency_type_querys()
+            except:
+                INCONSISTENCY_TYPE_QUERY = {}
+        finally:
+            INCONSISTENCY_LOCK.release()
+
         for type_id in bad_types:
             query = INCONSISTENCY_TYPE_QUERY.get(str(type_id))
             if query:

Modified: waska/trunk/waskaweb/model/phases_factory.py
===================================================================
--- waska/trunk/waskaweb/model/phases_factory.py	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/waskaweb/model/phases_factory.py	2008-09-08 13:24:26 UTC (rev 139)
@@ -164,7 +164,7 @@
         """ returns list of tuples (<symbol of phase>, <sql where clause>) """
         clauses = []
         for k, v in self.phases.iteritems():
-            where = " OR ".join([IS_FILLED % { 'name': name } for name in [i[0].getName() for i in v]])
+            where = " OR ".join(['(NOT %s)' % IS_FILLED % { 'name': name } for name in [i[0].getName() for i in v]])
             clauses.append((k, where))
         return clauses
 

Modified: waska/trunk/waskaweb/public/styles/all.css
===================================================================
--- waska/trunk/waskaweb/public/styles/all.css	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/waskaweb/public/styles/all.css	2008-09-08 13:24:26 UTC (rev 139)
@@ -492,3 +492,38 @@
 div.news {
 	margin-bottom: 1em;
 }
+
+/*----------------------*/
+/* Inconsistency	*/
+/*----------------------*/
+
+table.inconsistency {
+	margin: 0.3em 0.5em 0.3em 0.5em;
+}
+
+table.inconsistency th {
+	background:#d5d5d5; /**/
+	border-bottom:1px solid;
+}
+
+table.inconsistency td.count {
+	font-weight: normal;
+	text-align: right;
+	width: 7em;
+}
+
+table.inconsistency td.action {
+	font-weight: normal;
+	text-align: right;
+	width: 15em;
+}
+
+table.inconsistency td.type {
+	font-weight: normal;
+	text-align: left;
+	padding: 2.5 !important; /* would be overwritten by global td-setting */
+}
+
+div.inconsistency {
+	margin-bottom: 1em;
+}

Modified: waska/trunk/waskaweb/templates/casemanagement/listbadcases.mako
===================================================================
--- waska/trunk/waskaweb/templates/casemanagement/listbadcases.mako	2008-09-08 12:26:14 UTC (rev 138)
+++ waska/trunk/waskaweb/templates/casemanagement/listbadcases.mako	2008-09-08 13:24:26 UTC (rev 139)
@@ -1,90 +1,51 @@
 ## -*- coding: utf-8 -*-
+<%
+  headers = {'1':u'Fehlende Angabe zum Datum des Erstgespräch',
+             '2':u'Datum des Erstgespräch liegt in der Zukunft',
+             '3':u'Beendigungsdatum des CM liegt vor dem Datum des Erstgespräch',
+             '4':u'Beendigungsdatum des CM liegt in der Zukunft',
+             '5':u'CM ist beendet, aber keine Beendigungsdatum angegeben',
+             '6':u'CM ist nicht beendet, aber Beendigungsdatum angegeben',
+             '7':u'Die aktuelle Phase der Fallakte konnte aufgrund von fehlenden Angaben nicht festgestellt werden',
+             'clearing_start':u'Fehlende Pflichtfeldangaben für den Start der "Clearing" Phase',
+             'clearing_ende':u'Fehlende Pflichtfeldangaben für die Beendigung der "Clearing" Phase',
+             'beratung_start':u'Fehlende Pflichtfeldangaben für den Start der "Beratungs" Phase',
+             'beratung_ende':u'Fehlende Pflichtfeldangaben für die Beendigung der "Beratungs" Phase',
+             'cm_start':u'Fehlende Pflichtfeldangaben für den Start der "Case-Management" Phase',
+             'cm_ende':u'Fehlende Pflichtfeldangaben für die Beendigung der "Case-Management" Phase',
+             'nachbetreuung_start':u'Fehlende Pflichtfeldangaben für den Start der "Nachbetreuungs" Phase',
+             'nachbetreuung_ende':u'Fehlende Pflichtfeldangaben für die Beendigung der "Nachbetreuungs'}
+%>
 <%inherit file="../main.mako" />
 <div>
 <h1>Inkonsistente Fallakten finden</h1>
 <p>Mit Hilfe der folgenden Funktionen haben Sie die Möglichkeit inkonstente Fallakten zu identifizieren. Klicken Sie auf den "Anzeige"-Button des jeweiligen Type der Inkonsistenz, um eine Auflistung der betroffenen Fälle zu erhalten.</p>
 </div>
-%if len(c.type_1_list):
 <div>
-  <h2>Fehlende Angabe zum Datum des Erstgespräch</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:1">
-  <input type="submit" value="Anzeigen"> (${len(c.type_1_list)} Fallakte(n))
-  </form>
+  <table class="inconsistency">
+    <tr>
+      <th>Inkonsistenz</th>
+      <th style="width:4em;text-align:right">Anzahl</th>
+      <th style="width:7em;text-align:right">Aktion</th>
+    </tr>
+  <% count = 1 %>
+  %for k, v in c.inconsistency_types.iteritems():
+    %if len(v) > 0:
+      <tr>
+        <td class="type ${count%2 or 'table_row_h'}">${headers.get(k, k)}</td>
+        <td class="count ${count%2 or 'table_row_h'}">${len(v)}</td>
+        <td class="count ${count%2 or 'table_row_h'}">
+          <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
+            <input type="hidden" name="show_anonymized" value="1">
+            <input type="hidden" name="show_own" value="1">
+            <input type="hidden" name="show_open" value="1">
+            <input type="hidden" name="search_str" value="inconsistency:${k}">
+            <input type="submit" value="Anzeigen">
+          </form>
+        </td>
+      </tr>
+      <% count+=1 %>
+    %endif
+  %endfor
+</table>
 </div>
-%endif
-%if len(c.type_2_list):
-<div>
-  <h2>Datum des Erstgespräch liegt in der Zukunft</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:2">
-  <input type="submit" value="Anzeigen"> (${len(c.type_2_list)} Fallakte(n))
-  </form>
-</div>
-%endif
-%if len(c.type_3_list):
-<div>
-  <h2>Beendigungsdatum des CM liegt vor dem Datum des Erstgespräch</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:3">
-  <input type="submit" value="Anzeigen"> (${len(c.type_3_list)} Fallakte(n))
-  </form>
-</div>
-%endif
-%if len(c.type_4_list):
-<div>
-  <h2>Beendigungsdatum des CM liegt in der Zukunft</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:4">
-  <input type="submit" value="Anzeigen"> (${len(c.type_4_list)} Fallakte(n))
-  </form>
-</div>
-%endif
-%if len(c.type_5_list):
-<div>
-  <h2>CM ist beendet, aber keine Beendigungsdatum angegeben</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:5">
-  <input type="submit" value="Anzeigen"> (${len(c.type_5_list)} Fallakte(n))
-  </form>
-</div>
-%endif
-%if len(c.type_6_list):
-<div>
-  <h2>CM ist nicht beendet, aber Beendigungsdatum angegeben</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:6">
-  <input type="submit" value="Anzeigen"> (${len(c.type_6_list)} Fallakte(n))
-  </form>
-</div>
-%endif
-%if len(c.type_7_list):
-<div>
-  <h2>Die aktuelle Phase der Fallakte konnte aufgrund von fehlenden Angaben nicht festgestellt werden</h2>
-  <form name="list1" action="${h.url_for(controller="case_overview", action="search")}" method=post>
-  <input type="hidden" name="show_anonymized" value="1">
-  <input type="hidden" name="show_own" value="1">
-  <input type="hidden" name="show_open" value="1">
-  <input type="hidden" name="search_str" value="inconsistency:7">
-  <input type="submit" value="Anzeigen"> (${len(c.type_7_list)} Fallakte(n))
-  </form>
-</div>
-%endif



More information about the Mpuls-commits mailing list