def export_csv_line(self, patient): '''A line of CSV values representing this visit and patient. It is in the same order as export_csv_header. Use the patient passed in so that we can load patients in bulk. ''' assert patient.key() == self.parent_key() patient_line = util.csv_line(Visit._patient_prop_names, Patient.properties(), patient) visit_line = util.csv_line(Visit._visit_prop_names, Visit.properties(), self) visit_stats = self.get_visit_statistics() if visit_stats: visit_stats_line = util.csv_line(Visit._visit_stat_prop_names, VisitStatistics.properties(), self.get_visit_statistics()) else: visit_stat_props = [] for dummy in range(len(Visit.visit_stats_expanded_names())): visit_stat_props.append('') visit_stats_line = ",".join(visit_stat_props) return patient_line + "," + visit_line + "," + visit_stats_line
def visit_stats_expanded_names(): '''Expand Visit._visit_stat_props. Each ZscoreAndPercentileProperty gets two slots: x_zscore, x_percentile''' visit_stat_props = [] vsprops = VisitStatistics.properties() for prop in Visit._visit_stat_prop_names: # HACK(dan): Expand ZscoreAndPercentileProperty names into 2: # x_zscore, x_percentile # This is a hack because the printing actually takes place in # util.csv_line() if isinstance(vsprops[prop], ZscoreAndPercentileProperty): visit_stat_props.append('%s_zscore' % prop) visit_stat_props.append('%s_percentile' % prop) else: visit_stat_props.append(prop) return visit_stat_props