Esempio n. 1
0
    def test_person_form_event(self):
        redi.logger.info("Running " + __name__ +
                         "#test_person_form_event() using xml: ")
        string_1_xml = """
<person_form_event>
    <person>
        <study_id>100</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
 
        </all_form_events>
    </person>
    <person>
        <study_id>99</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                    <field>
                        <name>wbc_lborres</name>
                        <value>3.0</value>
                    </field>
                    <field>
                        <name>wbc_lbstat</name>
                        <value/>
                    </field>
                    <field>
                        <name>neut_lborres</name>
                        <value>500</value>
                    </field>
                    <field>
                        <name>neut_lbstat</name>
                        <value/>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>inr_lbdtc</name>
                        <value>1906-12-01</value>
                    </field>
                    <field>
                        <name>inr_lborres</name>
                        <value/>
                    </field>
                    <field>
                        <name>inr_lbstat</name>
                        <value>NOT_DONE</value>
                    </field>
                </event>
            </form>
        </all_form_events>
    </person>
    <person>
        <study_id>98</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value></value>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
        </all_form_events>
    </person>

</person_form_event>

"""
        #date_format = "%Y-%m-%d"
        #earliest_date   = datetime.datetime.strptime('1905-10-01', date_format).date()
        #latest_date     = datetime.datetime.strptime('1906-10-01', date_format).date()

        form_details = {'Total_cbc_Forms': 2, 'Total_inr_Forms': 3}
        subject_details = {
            '98': {
                'Total_cbc_Forms': 0,
                'Total_inr_Forms': 1
            },
            '99': {
                'Total_cbc_Forms': 1,
                'Total_inr_Forms': 1
            },
            '100': {
                'Total_cbc_Forms': 1,
                'Total_inr_Forms': 1
            }
        }

        report_data = {
            'total_subjects': 3,
            'form_details': form_details,
            'subject_details': subject_details,
            'errors': []
        }

        redcap_settings = {
            'rate_limiter_value_in_redcap': 500,
            'redcap_uri': 'http://*****:*****@example.com',
            'redcap_uri': 'http://*****:*****@example.com'
        }

        class MockDataRepository(object):
            def store(self, data):
                pass

        etree_1 = etree.ElementTree(etree.fromstring(string_1_xml))
        result = redi_lib.generate_output(etree_1, redcap_settings,
                                          email_settings, MockDataRepository())
        self.assertEqual(report_data['total_subjects'],
                         result['total_subjects'])
        self.assertEqual(report_data['form_details'], result['form_details'])
        self.assertEqual(report_data['subject_details'],
                         result['subject_details'])
        self.assertEqual(report_data['errors'], result['errors'])
Esempio n. 2
0
    def test_person_form_event(self):
        redi.logger.info("Running " + __name__ + "#test_person_form_event() using xml: ")
        string_1_xml = """
<person_form_event>
    <person>
        <study_id>100</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
 
        </all_form_events>
    </person>
    <person>
        <study_id>99</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                    <field>
                        <name>wbc_lborres</name>
                        <value>3.0</value>
                    </field>
                    <field>
                        <name>wbc_lbstat</name>
                        <value/>
                    </field>
                    <field>
                        <name>neut_lborres</name>
                        <value>500</value>
                    </field>
                    <field>
                        <name>neut_lbstat</name>
                        <value/>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>inr_lbdtc</name>
                        <value>1906-12-01</value>
                    </field>
                    <field>
                        <name>inr_lborres</name>
                        <value/>
                    </field>
                    <field>
                        <name>inr_lbstat</name>
                        <value>NOT_DONE</value>
                    </field>
                </event>
            </form>
        </all_form_events>
    </person>
    <person>
        <study_id>98</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value></value>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
        </all_form_events>
    </person>

</person_form_event>

"""

        form_details = {"Total_cbc_Forms": 2, "Total_inr_Forms": 3}
        subject_details = {
            "98": {"Total_cbc_Forms": 0, "Total_inr_Forms": 1},
            "99": {"Total_cbc_Forms": 1, "Total_inr_Forms": 1},
            "100": {"Total_cbc_Forms": 1, "Total_inr_Forms": 1},
        }

        report_data = {
            "total_subjects": 3,
            "form_details": form_details,
            "subject_details": subject_details,
            "errors": [],
        }

        class MockDataRepository(object):
            def store(self, data):
                pass

        class MockRedcapClient(RedcapClient):
            def __init__(self):
                self.project = TestGenerateOutput.dummyClass()

            def get_data_from_redcap(
                self,
                records_to_fetch=None,
                events_to_fetch=None,
                fields_to_fetch=None,
                forms_to_fetch=None,
                return_format="xml",
            ):
                raise NotImplementedError()

            def send_data_to_redcap(self, data, overwrite=False):
                return """Data sent"""

        etree_1 = etree.ElementTree(etree.fromstring(string_1_xml))
        result = redi_lib.generate_output(etree_1, MockRedcapClient(), 500, MockDataRepository())
        self.assertEqual(report_data["total_subjects"], result["total_subjects"])
        self.assertEqual(report_data["form_details"], result["form_details"])
        self.assertEqual(report_data["subject_details"], result["subject_details"])
        self.assertEqual(report_data["errors"], result["errors"])
Esempio n. 3
0
    def test_person_form_event(self):
        redi.logger.info("Running " + __name__ 
            + "#test_person_form_event() using xml: " )
        string_1_xml = """
<person_form_event>
    <person>
        <study_id>100</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
 
        </all_form_events>
    </person>
    <person>
        <study_id>99</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                    <field>
                        <name>wbc_lborres</name>
                        <value>3.0</value>
                    </field>
                    <field>
                        <name>wbc_lbstat</name>
                        <value/>
                    </field>
                    <field>
                        <name>neut_lborres</name>
                        <value>500</value>
                    </field>
                    <field>
                        <name>neut_lbstat</name>
                        <value/>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>inr_lbdtc</name>
                        <value>1906-12-01</value>
                    </field>
                    <field>
                        <name>inr_lborres</name>
                        <value/>
                    </field>
                    <field>
                        <name>inr_lbstat</name>
                        <value>NOT_DONE</value>
                    </field>
                </event>
            </form>
        </all_form_events>
    </person>
    <person>
        <study_id>98</study_id>
        <all_form_events>
            <form>
                <name>cbc</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value></value>
                    </field>
                </event>
            </form>
            <form>
                <name>inr</name>
                <event>
                    <name>1_arm_1</name>
                    <field>
                        <name>cbc_lbdtc</name>
                        <value>1905-10-01</value>
                    </field>
                </event>
            </form>
        </all_form_events>
    </person>

</person_form_event>

"""
        #date_format = "%Y-%m-%d"
        #earliest_date   = datetime.datetime.strptime('1905-10-01', date_format).date()
        #latest_date     = datetime.datetime.strptime('1906-10-01', date_format).date()

        form_details    = {'Total_cbc_Forms': 2, 'Total_inr_Forms': 3}
        subject_details = {
            '98'  : {'Total_cbc_Forms' : 0, 'Total_inr_Forms' : 1 },
            '99'  : {'Total_cbc_Forms' : 1, 'Total_inr_Forms' : 1 },
            '100' : {'Total_cbc_Forms' : 1, 'Total_inr_Forms' : 1 }
        } 
 
        report_data = {
            'total_subjects'        : 3,
            'form_details'          : form_details,
            'subject_details'       : subject_details,
            'errors'                : []
        }
        
        redcap_settings = {
            'rate_limiter_value_in_redcap':500,
            'redcap_uri':'http://*****:*****@example.com',
            'redcap_uri': 'http://*****:*****@example.com'
        }

        class MockDataRepository(object):
            def store(self, data):
                pass

        etree_1 = etree.ElementTree(etree.fromstring(string_1_xml))
        result = redi_lib.generate_output(etree_1, redcap_settings, email_settings, MockDataRepository())
        self.assertEqual(report_data['total_subjects'], result['total_subjects'])
        self.assertEqual(report_data['form_details'], result['form_details'])
        self.assertEqual(report_data['subject_details'], result['subject_details'])
        self.assertEqual(report_data['errors'], result['errors'])