Browse Source

patient list init

Fabian Peter Hammerle 6 years ago
commit
4f45cfdc12
4 changed files with 229 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 93 0
      create-list.py
  3. 11 0
      list.css
  4. 124 0
      patients.yml

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/list.html

+ 93 - 0
create-list.py

@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+
+import datetime as dt
+import os
+import yaml
+
+script_path = os.path.realpath(__file__)
+data_path = os.path.join(os.path.dirname(script_path), 'patients.yml')
+output_path = os.path.join(os.path.dirname(script_path), 'list.html')
+
+def random_date(start, end):
+    import random
+    return dt.date.fromordinal(random.randint(
+        start.toordinal(),
+        end.toordinal(),
+    ))
+
+class Patient:
+
+    def __init__(self, attr):
+        self.surname = attr.get('surname', None)
+        self.forename = attr.get('forename', None)
+        self.birth_date = attr.get('birth_date', None)
+        self.admission_date = attr.get('admission_date', None)
+        self.diagnosis = attr.get('diagnosis', None)
+        self.room = attr.get('room', None)
+        self.events = [Event(d) for d in attr.get('events', [])]
+
+    @property
+    def age_years(self):
+        if self.birth_date is None:
+            return None
+        else:
+            today = dt.date.today()
+            return today.year - self.birth_date.year \
+                - ((today.month, today.day) < (self.birth_date.month, self.birth_date.day))
+
+    @property
+    def admission_duration(self):
+        if self.admission_date is None:
+            return None
+        else:
+            return dt.date.today() - self.admission_date
+
+class Event:
+
+    def __init__(self, attr):
+        self.date = attr['date']
+        self.title = attr['title']
+
+    @property
+    def date_delta_str(self):
+        delta = dt.date.today() - self.date
+        if delta.days == 0:
+            return 'heute'
+        elif delta.days < 0:
+            return '{}d prae'.format(abs(delta.days))
+        else:
+            return '{}d post'.format(delta.days)
+
+    @property
+    def label(self):
+        return '{} {}'.format(self.date_delta_str, self.title)
+
+def main():
+    with open(data_path, 'r') as f:
+        patients = yaml.load(f.read())
+    patients.sort(key=lambda p: p.get('room', 0))
+    doc = '''
+    <!DOCTYPE html>
+    <html>
+    <head><link rel="stylesheet" href="list.css" /></head>
+    <body>
+        <table>
+    '''
+    for p in [Patient(d) for d in patients]:
+        doc += '<tr><td>{}</td></tr>'.format('</td><td>'.join([
+            '<b>{}</b>'.format(p.room) if p.room else '',
+            p.surname or '',
+            p.forename or '',
+            '{}a'.format(p.age_years) if p.birth_date else '',
+            '{}d'.format(p.admission_duration.days) if p.admission_date else '',
+            '; '.join(
+                ([p.diagnosis] if p.diagnosis else [])
+                    + [e.label for e in sorted(p.events, key=lambda e: e.date)]
+            )
+        ]))
+    doc += '</table></body></html>'
+    with open(output_path, 'w') as f:
+        f.write(doc)
+
+if __name__ == '__main__':
+    main()

+ 11 - 0
list.css

@@ -0,0 +1,11 @@
+body {
+    line-height: 150%;
+}
+
+table {
+    width: 100%;
+}
+
+table td {
+    border-bottom: 0.5pt solid black;
+}

+ 124 - 0
patients.yml

@@ -0,0 +1,124 @@
+- forename: Devon
+  surname: Omeara
+  birth_date: 1978-12-20
+  room: 14
+  diagnosis: VS L4/5
+  admission_date: 2018-04-15
+- forename: Kylie
+  surname: Mcguigan
+  birth_date: 1954-11-08
+  room: 15
+  diagnosis: DP L5/S1
+  admission_date: 2018-04-22
+  events:
+  - {date: 2018-04-24, title: MR LWS}
+  - {date: 2018-04-26, title: DE L5/S1}
+  - {date: 2018-04-28, title: E}
+- forename: Leticia
+  surname: Leclair
+  birth_date: 1982-05-09
+  room: 16
+  diagnosis: VS L3/4
+  admission_date: 2018-04-22
+- forename: Cindi
+  surname: Hammell
+  birth_date: 1966-10-26
+  room: 16
+  diagnosis: DP L4/L5 li
+  admission_date: 2018-04-21
+- forename: Deanne
+  surname: Awong
+  room: 16
+  diagnosis: RF re parietal
+  admission_date: 2018-04-25
+  events:
+  - {date: 2018-04-25, title: Duplex-Sono}
+  - {date: 2018-04-30, title: Staging-CT}
+  - {date: 2018-05-01, title: MR-Fid}
+  - {date: 2018-05-02, title: Biopsie}
+- forename: Pamella
+  surname: Ogawa
+  birth_date: 1966-08-08
+  room: 17
+  diagnosis: VS L4/5
+  admission_date: 2018-04-16
+- surname: Rink
+  birth_date: 1948-12-27
+  room: 17
+  diagnosis: DP L5/S1
+  admission_date: 2018-04-15
+- forename: Francina
+  surname: Betton
+  birth_date: 1975-08-12
+  room: 20
+  diagnosis: VS L3/4/5
+  admission_date: 2018-04-19
+- forename: Rodrick
+  surname: Troxler
+  birth_date: 1944-02-10
+  room: 20
+  diagnosis: VS L3/4/5
+  admission_date: 2018-04-22
+- forename: Giselle
+  surname: Pigman
+  birth_date: 1969-04-25
+  room: 20
+  diagnosis: DP L5/S1
+  admission_date: 2018-04-25
+- forename: Alonso
+  surname: Quesnel
+  birth_date: 1923-06-18
+  room: 20
+  diagnosis: VS L3/4
+  admission_date: 2018-04-19
+- forename: Pearlie
+  birth_date: 1979-05-27
+  room: 20
+  diagnosis: VS L4/5
+  admission_date: 2018-04-19
+- forename: Evelin
+  surname: Boe
+  birth_date: 1982-01-17
+  room: 21
+  diagnosis: DP L4/L5 re
+  admission_date: 2018-04-25
+- forename: Shanta
+  surname: Stayer
+  birth_date: 1945-12-10
+  room: 21
+  diagnosis: VS L3/4
+  admission_date: 2018-04-22
+- forename: Renna
+  surname: Fyffe
+  birth_date: 1955-11-08
+  room: 21
+  diagnosis: VS L3/4/5
+- forename: Beau
+  surname: Ratley
+  birth_date: 1968-05-11
+  room: 22
+  diagnosis: VS L3/4/5
+  admission_date: 2018-04-22
+- forename: Charlotte
+  surname: Keep
+  birth_date: 1954-04-26
+  room: 22
+  diagnosis: VS L3/4/5
+  admission_date: 2018-04-22
+- forename: Lenny
+  surname: Farber
+  birth_date: 1952-04-09
+  room: 22
+  diagnosis: DP L4/L5 re
+  admission_date: 2018-04-25
+- forename: Yen
+  surname: Aquirre
+  birth_date: 1971-05-26
+  room: 23
+  diagnosis: VS L3/4/5
+  admission_date: 2018-04-21
+- forename: Tiffanie
+  surname: Cabiness
+  birth_date: 1983-11-03
+  room: 23
+  admission_date: 2018-04-22