[Mpuls-commits] r3895 - in wasko/trunk: . waskoweb/controllers waskoweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 6 12:17:20 CEST 2010


Author: roland
Date: 2010-10-06 12:17:20 +0200 (Wed, 06 Oct 2010)
New Revision: 3895

Added:
   wasko/trunk/waskoweb/controllers/mpuls.py
   wasko/trunk/waskoweb/model/appointment.py
Modified:
   wasko/trunk/ChangeLog
   wasko/trunk/wasko.json
   wasko/trunk/waskoweb/controllers/formularpage.py
Log:
issue933: reminders for long CMs are generated on-the-fly

Modified: wasko/trunk/ChangeLog
===================================================================
--- wasko/trunk/ChangeLog	2010-10-06 09:47:47 UTC (rev 3894)
+++ wasko/trunk/ChangeLog	2010-10-06 10:17:20 UTC (rev 3895)
@@ -1,3 +1,14 @@
+2010-10-06 Roland Geider <roland.geider at intevation.de>
+
+	* waskoweb/model/appointment.py,
+	  waskoweb/controllers/mpuls.py,
+	  waskoweb/controllers/formularpage.py,
+	  waskoweb/templates/info,
+	  wasko.json: issue933: reminders for too long CM phases are generated
+	  on-the-fly on the overview page and not as actual DB entries (see
+	  also issue807)
+
+
 2010-09-29  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* waskoweb/templates/casemanagement/main.mako,

Modified: wasko/trunk/wasko.json
===================================================================
--- wasko/trunk/wasko.json	2010-10-06 09:47:47 UTC (rev 3894)
+++ wasko/trunk/wasko.json	2010-10-06 10:17:20 UTC (rev 3895)
@@ -8,7 +8,7 @@
 	},
 	"case-module": {
 		"import": "1",
-		"reminders": "0",
+		"reminders": "1",
 		"appointments": "1",
 		"exportXLS": "1",
 		"exportCSV": "0",

Modified: wasko/trunk/waskoweb/controllers/formularpage.py
===================================================================
--- wasko/trunk/waskoweb/controllers/formularpage.py	2010-10-06 09:47:47 UTC (rev 3894)
+++ wasko/trunk/waskoweb/controllers/formularpage.py	2010-10-06 10:17:20 UTC (rev 3895)
@@ -105,99 +105,12 @@
             session['uncommited_fields'] = instance_tree.commit()
             session.save()
 
-        self._create_appointments_for_too_long_cm(case_id, form_result)
-
         phase_changed = self._handle_automatic_phase_change(page_id)
         if phase_changed:
             return phase_changed
 
         return self.select(page_id)
 
-    def _create_appointments_for_too_long_cm(self, case_id, form_result):
-        """Create appointments for cases that have been in CM for too long.
-        """
-        if (u'datum_cm_start:%s' % case_id in form_result or
-                u'datum_cm_ende:%s' % case_id in form_result or
-                u'cm_datum_verlaengerung_1:%s' % case_id in form_result or 
-                u'cm_datum_verlaengerung_2:%s' % case_id in form_result):
-            conn = db.getConnection()
-            cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-            cur.execute('''SELECT datum_cm_start,
-                                datum_cm_ende,
-                                cm_datum_verlaengerung_1,
-                                cm_datum_verlaengerung_2,
-                                fn,
-                                name,
-                                vorname
-                            FROM master_tbl_view
-                            WHERE id = %s''' % (case_id))
-            case_data = cur.fetchall()[0]
-            
-            # log.debug('case_data: %s' % case_data)
-            #max([date for date in case_data[:3] if date != None])
-            date_cm_start    = case_data[0] or datetime.date.today()
-            date_cm_end      = case_data[1] or datetime.date.today()
-            date_extension_1 = case_data[2]
-            date_extension_2 = case_data[3]
-            
-            
-            # Maximum of 18 months with 2 extensions
-            if (date_extension_1 != None and date_extension_2 != None):
-                end_date = date_extension_2
-                max_time_delta = datetime.timedelta(18*31)
-            # Maximum of 15 months with 1 extension
-            elif (date_extension_1 != None and date_extension_2 == None):
-                end_date = date_extension_1
-                max_time_delta = datetime.timedelta(15*31)
-            # Everything else, 12 months
-            else:
-                end_date = date_cm_end
-                max_time_delta = datetime.timedelta(365)
-            
-            if end_date - date_cm_start > max_time_delta:
-                appointment_factory = CaseAppointmentFactory()
-                
-                # Use the first date from the DB as it is properly validated
-                # Try first to load the existing appointment and overwrite its data
-                # if one is found
-                #
-                # Searching by name and hoping that it didn't change is... ugly
-                search_appointment_sql = u"""SELECT id
-                        FROM ka_fall_termine_tbl_view
-                        WHERE name LIKE 'Zu langer Case-Management der Fallakte %s' 
-                            AND art = 1
-                            AND master_id = %s"""  % (case_data[4], case_id)
-                
-                cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-                cur.execute(search_appointment_sql)
-                appointments = cur.fetchall()
-                
-                appointment = appointment_factory.createNew(case_id)
-                # Found appointment, update
-                if appointments:
-                    appointment_id = appointments[0].pop() #ideally, we are cleverer
-                    appointment = appointment_factory.loadById(appointment_id)
-                # No appointment found, new one
-                else:
-                    appointment = appointment_factory.createNew(case_id)
-                
-                appointment_data = {'description': u'''Bitte überprüfen Sie die
-                eingetragenen Datumsangaben, die Fallakte %s von %s %s 
-                überschreitet die maximale Dauer der Phase Case-Management
-                von 12 Monaten.''' % (case_data[4], case_data[5], case_data[6]),
-                'title': u'Zu langer Case-Management der Fallakte %s' % case_data[4],
-                'case_id': case_id,
-                'start_time': datetime.time(00, 00),
-                'start_date': date_cm_end + max_time_delta,
-                'end_time': None,
-                'end_date': None,
-                'type': u'1', #reminder
-                'id': u''
-                }
-            
-                appointment.setData(appointment_data)
-                appointment.store()
-
     def _handle_evaluation_number(self, case_id, form_result):
         """Set or Reset the evaluation number if the form_result is for page 2
         """

Added: wasko/trunk/waskoweb/controllers/mpuls.py
===================================================================
--- wasko/trunk/waskoweb/controllers/mpuls.py	2010-10-06 09:47:47 UTC (rev 3894)
+++ wasko/trunk/waskoweb/controllers/mpuls.py	2010-10-06 10:17:20 UTC (rev 3895)
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
+# Web-Anwendungs-Server fuer Kompetenzagenturen).
+#
+# mpuls WASKA is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
+#
+# mpuls WASKA has been developed on behalf of the
+# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
+# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
+# European Social Fund resources.
+#
+# Authors:
+# Torsten Irländer <torsten.irlaender at intevation.de>
+#
+
+import logging
+
+from pylons import tmpl_context as c, app_globals as g
+
+from mpulsweb.model.appointment import MaxSaveTimeReminderOverview, \
+                CaseReminderOverview
+from mpulsweb.lib.base import BaseController, render, session
+from mpulsweb.controllers.mpuls import MpulsController
+import mpulsweb.lib.helpers as h
+from waskoweb.model.appointment import CaseReminderMaxLength
+
+log = logging.getLogger(__name__)
+
+
+class MpulsController(MpulsController):
+
+    def get_reminders(self):
+        """Return an AppointmentOverview instance with reminders.
+        The overview always contains the max save time reminders.
+        """
+        
+        remindlist = MaxSaveTimeReminderOverview()
+        remindlist.join(CaseReminderMaxLength())
+        remindlist.sort()
+        return remindlist
+
+

Added: wasko/trunk/waskoweb/model/appointment.py
===================================================================
--- wasko/trunk/waskoweb/model/appointment.py	2010-10-06 09:47:47 UTC (rev 3894)
+++ wasko/trunk/waskoweb/model/appointment.py	2010-10-06 10:17:20 UTC (rev 3895)
@@ -0,0 +1,142 @@
+# -*- coding: utf-8 -*-
+# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
+# Web-Anwendungs-Server fuer Kompetenzagenturen).
+#
+# mpuls WASKA is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
+#
+# mpuls WASKA has been developed on behalf of the
+# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
+# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
+# European Social Fund resources.
+#
+# Authors:
+# Torsten Irländer <torsten.irlaender at intevation.de>
+#
+
+import logging
+from datetime import datetime, timedelta
+
+import mpulsweb.lib.helpers as h
+from mpulsweb.lib.base import session, g
+from mpulsweb.lib.db import db
+from mpulsweb.model.case import MpulsCaseOverview
+from mpulsweb.model.appointment import AppointmentOverview, CaseAppointmentFactory
+from mpulsweb.controllers.case_overview import default_phases
+
+GET_MAX_CM_CASES_NO_EXTENSIONS = """
+SELECT id,
+    ABS(extract(day from (datum_cm_start - coalesce(datum_cm_ende,
+            now())))) AS dauer
+FROM master_tbl_view
+WHERE
+    ABS(extract(day from (datum_cm_start - coalesce(datum_cm_ende,
+            now())))) > 365
+    AND cm_datum_verlaengerung_1 IS NULL
+    AND cm_datum_verlaengerung_2 IS NULL;
+"""
+
+GET_MAX_CM_CASES_1_EXTENSION = """
+SELECT id,
+    ABS(extract(day from (datum_cm_start - coalesce(cm_datum_verlaengerung_1,
+            now())))) AS dauer
+FROM master_tbl_view
+WHERE
+    ABS(extract(day from (datum_cm_start - coalesce(cm_datum_verlaengerung_1,
+            now())))) > 31*15
+    AND cm_datum_verlaengerung_1 IS NOT NULL
+    AND cm_datum_verlaengerung_2 IS NULL;
+"""
+
+GET_MAX_CM_CASES_2_EXTENSIONS = """
+SELECT id,
+    ABS(extract(day from (datum_cm_start - coalesce(cm_datum_verlaengerung_2,
+            now())))) AS dauer
+FROM master_tbl_view
+WHERE
+    ABS(extract(day from (datum_cm_start - coalesce(cm_datum_verlaengerung_2,
+            now())))) > 31*18
+    AND cm_datum_verlaengerung_1 IS NOT NULL
+    AND cm_datum_verlaengerung_2 IS NOT NULL;
+"""
+
+log = logging.getLogger(__name__)
+
+
+
+class CaseReminderMaxLength(AppointmentOverview):
+
+    def __init__(self):
+        self.appointment_list = []
+        cases = MpulsCaseOverview()
+        user = session['USER_AUTHORIZED']
+        
+        # Cases with 2 extensions, 18 months maximum
+        cases_2_extensions = self.get_cases(GET_MAX_CM_CASES_2_EXTENSIONS)
+        max_duration = 18*31
+        for case_id in cases_2_extensions:
+            duration = cases_2_extensions[case_id].get('dauer')
+            self.appointment_list.append(self.make_extension_appointment(case_id,
+                                                        duration, max_duration))
+            
+        # Cases with 1 extension, 15 months maximum
+        cases_1_extension = self.get_cases(GET_MAX_CM_CASES_1_EXTENSION)
+        max_duration = 15*31
+        for case_id in cases_1_extension:
+            duration = cases_1_extension[case_id].get('dauer')
+            self.appointment_list.append(self.make_extension_appointment(case_id,
+                                                        duration, max_duration))
+        
+        # Cases with no extensions, 12 months maximum
+        cases_no_extensions = self.get_cases(GET_MAX_CM_CASES_NO_EXTENSIONS)
+        max_duration = 365
+        for case_id in cases_no_extensions:
+            duration = cases_no_extensions[case_id].get('dauer')
+            self.appointment_list.append(self.make_extension_appointment(case_id,
+                                                        duration, max_duration))
+        
+    
+    def get_cases(self, sql):
+        conn, cur = None, None
+        list = {}
+        try:
+            conn = db.getConnection()
+            cur = conn.cursor()
+            cur.execute(sql)
+            
+            result = cur.fetchall()
+            for r in result:
+                list[r[0]] = {'dauer': r[1]}
+            return list
+        finally:
+            db.recycleConnection(conn, cur)
+        return False
+
+    def make_extension_appointment(self, case_id, duration, max_duration):
+        factory = CaseAppointmentFactory()
+        type = 1
+        case = g.case_factory.loadById(case_id)
+        title = u"Zu langer Case-Management der Fallakte von %s, %s" %\
+                                            (case.last_name, case.first_name)
+        
+        description = u''' Die Fallakte überschreitet mit %.f Tagen die maximale
+                Dauer der Phase Case-Management von %s Tagen.''' % \
+                (duration, max_duration)
+        appointment = factory.createByData(None, title, datetime.now(), None,
+                                            description, case.id, type)
+        return appointment
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8:



More information about the Mpuls-commits mailing list