Example #1
0
 def export_table(self):
     """
     Returns a multi-dimensional list formatted as export_from_tables would expect. It includes all context
     (study data and subjects) required to render an ODM document.
     """
     tz = get_timezone_for_user(None, self.domain)
     now = datetime.now(tz)
     file_oid = now.strftime('CommCare_%Y%m%d%H%M%S%z')
     utc_offset = now.strftime('%z')
     with_colon = ':'.join((utc_offset[:-2], utc_offset[-2:]))  # Change UTC offset from "+0200" to "+02:00"
     study_details = {
         'file_oid': file_oid,
         'file_description': 'Data imported from CommCare',
         'creation_datetime': now.strftime('%Y-%m-%dT%H:%M:%S') + with_colon,
         'study_name': get_study_constant(self.domain, 'study_name'),
         'study_description': get_study_constant(self.domain, 'study_description'),
         'protocol_name': get_study_constant(self.domain, 'protocol_name'),
         'study_oid': get_study_constant(self.domain, 'study_oid'),
         'audit_logs': AUDIT_LOGS,
     }
     return [
         [
             'study',  # The first "sheet" is the study details. It has only one row.
             [study_details.keys(), study_details.values()]
         ],
         [
             'subjects',
             [self.subject_headers()] + list(self.export_rows)
         ]
     ]
Example #2
0
    def _init(self):
        from custom.openclinica.utils import get_study_constant

        # We don't need to keep track of tables because we only have two: "study" contains context, and
        # "subjects" of which each row is a study subject. Initialise template context instead of tables.
        self.context = {
            'subjects': [],
            # The template accepts XML strings in params "study_xml" and "admin_data_xml" which are
            # study-specific. We parse these from the study metadata, which, for this first OpenClinica
            # project, is stored in custom/openclinica/study_metadata.xml. In future projects we will need to store
            # study metadata for each domain that uses OpenClinica integration.
            'study_xml': get_study_constant(domain=None, name='study_xml'),
            'admin_data_xml': get_study_constant(domain=None, name='admin_data_xml'),
        }
        # We'll keep the keys from the header rows of both tables, so that we can zip them up with the rest of the
        # rows to create dictionaries for the ODM XML template
        self.study_keys = []
        self.subject_keys = []
Example #3
0
    def __init__(self, request, base_context=None, domain=None, **kwargs):
        super(OdmExportReportView, self).__init__(request, base_context, domain, **kwargs)

        tz = get_timezone_for_user(None, self.domain)
        now = datetime.now(tz)
        file_oid = now.strftime('CommCare_%Y%m%d%H%M%S%z')
        utc_offset = now.strftime('%z')
        with_colon = ':'.join((utc_offset[:-2], utc_offset[-2:]))  # Change UTC offset from "+0200" to "+02:00"
        self.study_details = {
            'file_oid': file_oid,
            'file_description': 'Data imported from CommCare',
            'creation_datetime': now.strftime('%Y-%m-%dT%H:%M:%S') + with_colon,
            'study_name': get_study_constant(domain, 'study_name'),
            'study_description': get_study_constant(domain, 'study_description'),
            'protocol_name': get_study_constant(domain, 'protocol_name'),
            'study_oid': get_study_constant(domain, 'study_oid'),
            'audit_logs': AUDIT_LOGS,
        }
Example #4
0
 def export_table(self):
     """
     Returns a multi-dimensional list formatted as export_from_tables would expect. It includes all context
     (study data and subjects) required to render an ODM document.
     """
     tz = get_timezone_for_user(None, self.domain)
     now = datetime.now(tz)
     file_oid = now.strftime('CommCare_%Y%m%d%H%M%S%z')
     utc_offset = now.strftime('%z')
     with_colon = ':'.join((utc_offset[:-2], utc_offset[-2:]))  # Change UTC offset from "+0200" to "+02:00"
     study_details = {
         'file_oid': file_oid,
         'file_description': 'Data imported from CommCare',
         'creation_datetime': now.strftime('%Y-%m-%dT%H:%M:%S') + with_colon,
         'study_name': get_study_constant(self.domain, 'study_name'),
         'study_description': get_study_constant(self.domain, 'study_description'),
         'protocol_name': get_study_constant(self.domain, 'protocol_name'),
         'study_oid': get_study_constant(self.domain, 'study_oid'),
         'audit_logs': AUDIT_LOGS,
         # The template accepts XML strings in params "study_xml" and
         # "admin_data_xml" which come from the study metadata.
         'study_xml': get_study_constant(self.domain, 'study_xml'),
         'admin_data_xml': get_study_constant(self.domain, 'admin_data_xml'),
         'domain': self.domain,
     }
     return [
         [
             'study',  # The first "sheet" is the study details. It has only one row.
             [list(study_details.keys()), list(study_details.values())]
         ],
         [
             'subjects',
             [self.subject_headers()] + list(self.export_rows)
         ]
     ]