1
2
3 __author__ = "Karsten Hilbert"
4 __license__ = 'GPL'
5
6 from Gnumed.pycommon import gmPG
7
8
9 pool = gmPG.ConnectionPool()
10
11 filename = 'immunization-data.txt'
12 print "Writing immunization metadata to:", filename
13 f = open(filename, 'w')
14
15 vaccine_template = """
16 Vaccine "%s" (%s)
17 comment : %s
18 given via: %s (%s = %s)
19 age range: %s days - %s days
20 """
21
22 schedule_template = """
23 Schedule "%s" (%s)
24 indication : %s (%s)
25 start @ age: %s days
26 # of shots : %s
27 comment : %s
28 """
29
30
31
32
33
34
35 cmd = "select * from clin.v_vaccine"
36 vaccine_rows, idx = gmPG.run_ro_query (
37 link_obj = 'clinical',
38 aQuery = cmd,
39 get_col_idx = True
40 )
41
42 if vaccine_rows is None:
43 print "error retrieving vaccine data"
44
45 else:
46 f.write('Vaccines in the GNUmed database\n')
47 f.write('-------------------------------\n')
48 for vacc in vaccine_rows:
49 f.write(vaccine_template % (
50 vacc[idx['trade_name']],
51 vacc[idx['short_name']],
52 vacc[idx['comment']],
53 vacc[idx['l10n_route_description']],
54 vacc[idx['route_abbreviation']],
55 vacc[idx['route_description']],
56 vacc[idx['min_age']].day,
57 vacc[idx['max_age']].day
58 ))
59 if vacc[idx['is_live']] is None:
60 f.write(" type of vaccine not known\n")
61 elif vacc[idx['is_live']]:
62 f.write(" Cave: live vaccine\n")
63 else:
64 f.write(" non-live vaccine\n")
65
66 cmd = """select * from clin.v_inds4vaccine where pk_vaccine = %s"""
67 indication_rows, ind_idx = gmPG.run_ro_query (
68 'clinical',
69 cmd,
70 True,
71 vacc[idx['pk_vaccine']]
72 )
73
74 if indication_rows is None:
75 print "error retrieving vaccine indication data"
76
77 else:
78 f.write(' Indications:\n')
79 for ind in indication_rows:
80 f.write(' - %s (%s)\n' % (ind[ind_idx['l10n_indication']], ind[ind_idx['indication']]))
81
82
83
84
85
86
87 cmd = "select * from clin.v_vacc_regimes"
88 schedule_rows, idx = gmPG.run_ro_query (
89 'clinical',
90 cmd,
91 True
92 )
93 if schedule_rows is None:
94 print "error retrieving vaccination schedules"
95 else:
96 f.write('\n\nVaccination schedules in the GNUmed database\n')
97 f.write( '--------------------------------------------\n')
98 for sched in schedule_rows:
99 if sched[idx['is_active']]:
100 act = 'active'
101 else:
102 act = 'inactive'
103 f.write(schedule_template % (
104 sched[idx['regime']],
105 act,
106 sched[idx['l10n_indication']],
107 sched[idx['indication']],
108 sched[idx['min_age_due']],
109 sched[idx['shots']],
110 sched[idx['comment']]
111 ))
112
113 cmd = "select * from clin.v_vacc_defs4reg where pk_regime=%s order by vacc_seq_no"
114 shot_rows, shots_idx = gmPG.run_ro_query (
115 'clinical',
116 cmd,
117 True,
118 sched[idx['pk_regime']]
119 )
120 if shot_rows is None:
121 print "error retrieving shots for regime"
122 else:
123 f.write(' Shots defined for this schedule:\n')
124 for shot in shot_rows:
125 if shot[shots_idx['is_booster']]:
126 f.write(' booster) start %s - %s days of age, refresh after %s (%s)\n' % (
127 shot[shots_idx['age_due_min']].day,
128 shot[shots_idx['age_due_max']].day,
129 shot[shots_idx['min_interval']].day,
130 shot[shots_idx['vacc_comment']]
131 ))
132 elif shot[shots_idx['vacc_seq_no']] == 1:
133 f.write(' shot #%s) due between day %s and %s (%s)\n' % (
134 shot[shots_idx['vacc_seq_no']],
135 shot[shots_idx['age_due_min']].day,
136 shot[shots_idx['age_due_max']].day,
137 shot[shots_idx['vacc_comment']]
138 ))
139 else:
140 f.write(' shot #%s) due between day %s and %s, minimum %s day after previous (%s)\n' % (
141 shot[shots_idx['vacc_seq_no']],
142 shot[shots_idx['age_due_min']].day,
143 shot[shots_idx['age_due_max']].day,
144 shot[shots_idx['min_interval']].day,
145 shot[shots_idx['vacc_comment']]
146 ))
147
148 cmd = """
149 select trade_name, short_name
150 from ref.vaccine
151 where
152 select () = ()
153 """
154
155 f.close()
156