[vtimeline] Add survival data, closes #4084902 cubicweb-brainomics-debian-version-0.11.2-1 cubicweb-brainomics-version-0.11.2
authorVincent Michel <vincent.michel@logilab.fr>
Wed, 02 Jul 2014 14:36:26 +0000
changeset 1131 bb0a3a17febe
parent 1130 6337ca8639e1
child 1132 27ecd0d83b47
[vtimeline] Add survival data, closes #4084902
views/vtimeline.py
--- a/views/vtimeline.py	Wed Jul 02 14:32:45 2014 +0000
+++ b/views/vtimeline.py	Wed Jul 02 14:36:26 2014 +0000
@@ -28,6 +28,7 @@
 
         def call(self):
             dates = []
+            # Date format is %Y,%m,%d for vtimeline sake
             d = {'timeline': {'headline': '', 'type': 'default', 'text': '', 'date': dates}}
             for entity in self.cw_rset.entities():
                 # Subject dates
@@ -74,6 +75,15 @@
                             if date:
                                 dates.append({'startDate': ustrftime(date, '%Y,%m,%d'),
                                               'headline': drugtake.view('incontext')})
+                # SurvivalData
+                for surv in entity.reverse_survival_of:
+                    if surv.lastnews_date:
+                        title = []
+                        for attr in ('state_at_lastnews', 'deceased', 'relapse_date'):
+                            if getattr(surv, attr) is not None:
+                                title.append('%s - %s' % (self._cw._(attr), getattr(surv, attr)))
+                        dates.append({'startDate': ustrftime(surv.lastnews_date, '%Y,%m,%d'),
+                                      'headline': '<br/>'.join(title)})
                 # Add additional data
                 self.additional_infos(entity, d)
             self.w(json.dumps(d))