Example #1
0
 def test_research_id_to_redcap_id_converter_mail_key_error(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     email_settings = {}
     redcap_settings = {}
     redcap_settings['redcap_uri'] = 'https://example.org/redcap/api/'
     redcap_settings['token'] = 'ABCDEF878D219CFA5D3ADF7F9AB12345'
     self.assertRaises(Exception,redi.research_id_to_redcap_id_converter,self.data,redcap_settings,email_settings, self.research_id_to_redcap_id, False, self.configuration_directory)
 def test_create_empty_event_tree_for_study_for_zero_subjects(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.zero_subjects = """<?xml version='1.0' encoding='US-ASCII'?>
     <study></study>
     """
     self.data_zero_subjects = etree.ElementTree(etree.fromstring(self.zero_subjects))
     self.assertRaises(Exception,redi.create_empty_event_tree_for_study,self.data_zero_subjects,self.data_all_form_events)
 def test_create_empty_events_for_one_subject_all_fields_input(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.result = etree.tostring(
         redi.create_empty_events_for_one_subject(self.data1_test1,
                                                  self.data2_test1))
     self.result = ''.join(self.result.split())
     self.expect_test1 = ''.join(self.expect_test1.split())
     self.assertEqual(self.expect_test1, self.result)
Example #4
0
 def test_create_empty_event_tree_for_study_for_zero_subjects(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.zero_subjects = """<?xml version='1.0' encoding='US-ASCII'?>
     <study></study>
     """
     self.data_zero_subjects = etree.ElementTree(
         etree.fromstring(self.zero_subjects))
     self.assertRaises(Exception, redi.create_empty_event_tree_for_study,
                       self.data_zero_subjects, self.data_all_form_events)
Example #5
0
    def test_parse_form_events(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        logger.info("Running " + __name__ +
                    "#test_person_form_event() using xml: ")
        string_1_xml = """<?xml version="1.0" encoding="UTF-8"?>
<redcapProject>
	<name>Project</name>
	<form>
		<name>cbc</name>
		<formDateField>cbc_lbdtc</formDateField>
		<formCompletedFieldName>cbc_complete</formCompletedFieldName>
		<formImportedFieldName>cbc_nximport</formImportedFieldName>
        <formCompletedFieldValue>2</formCompletedFieldValue>
        <formImportedFieldValue>Y</formImportedFieldValue>
		<event>
    		<name>1_arm_1</name>
		</event>
		<event>
		    <name>2_arm_1</name>
		</event>
		<event>
		    <name>3_arm_1</name>
		</event>
	</form>
	<form>
		<name>chemistry</name>
		<formDateField>chem_lbdtc</formDateField>
		<formCompletedFieldName>chemistry_complete</formCompletedFieldName>
		<formImportedFieldName>chem_nximport</formImportedFieldName>
        <formCompletedFieldValue>2</formCompletedFieldValue>
        <formImportedFieldValue>Y</formImportedFieldValue>
		<event>
		    <name>1_arm_1</name>
		</event>
		<event>
		    <name>2_arm_1</name>
		</event>
    </form>
</redcapProject>
"""
        temp_file = 'tmp.xml'
        fh = open(temp_file, 'w')
        fh.write(string_1_xml)
        fh.close()

        etree_1 = etree.ElementTree(etree.fromstring(string_1_xml))
        result_tree = redi.parse_form_events(temp_file)
        result_xml = etree.tostring(result_tree)

        par = etree.XMLParser(remove_blank_text=True)
        clean_tree = etree.XML(string_1_xml, parser=par)
        clean_result = etree.XML(result_xml, parser=par)

        self.assertEqual(etree.tostring(clean_tree),
                         etree.tostring(clean_result))
        os.remove(temp_file)
Example #6
0
 def test_research_id_to_redcap_id_converter(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     email_settings = {}
     redcap_settings = {}
     redcap_settings['redcap_uri'] = 'https://example.org/redcap/api/'
     redcap_settings['token'] = 'ABCDEF878D219CFA5D3ADF7F9AB12345'
     redcap_settings['verify_ssl'] = False
     redi.research_id_to_redcap_id_converter(self.data, redcap_settings, email_settings, self.research_id_to_redcap_id, False, self.configuration_directory)
     result = etree.tostring(self.data)
     self.assertEqual(self.expect, result)
Example #7
0
    def test_parse_form_events(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        logger.info("Running " + __name__ 
            + "#test_person_form_event() using xml: " )
        string_1_xml = """<?xml version="1.0" encoding="UTF-8"?>
<redcapProject>
	<name>Project</name>
	<form>
		<name>cbc</name>
		<formDateField>cbc_lbdtc</formDateField>
		<formCompletedFieldName>cbc_complete</formCompletedFieldName>
		<formImportedFieldName>cbc_nximport</formImportedFieldName>
        <formCompletedFieldValue>2</formCompletedFieldValue>
        <formImportedFieldValue>Y</formImportedFieldValue>
		<event>
    		<name>1_arm_1</name>
		</event>
		<event>
		    <name>2_arm_1</name>
		</event>
		<event>
		    <name>3_arm_1</name>
		</event>
	</form>
	<form>
		<name>chemistry</name>
		<formDateField>chem_lbdtc</formDateField>
		<formCompletedFieldName>chemistry_complete</formCompletedFieldName>
		<formImportedFieldName>chem_nximport</formImportedFieldName>
        <formCompletedFieldValue>2</formCompletedFieldValue>
        <formImportedFieldValue>Y</formImportedFieldValue>
		<event>
		    <name>1_arm_1</name>
		</event>
		<event>
		    <name>2_arm_1</name>
		</event>
    </form>
</redcapProject>
"""
        temp_file = 'tmp.xml'
        fh = open(temp_file, 'w')
        fh.write(string_1_xml)
        fh.close()

        etree_1 = etree.ElementTree(etree.fromstring(string_1_xml))
        result_tree = redi.parse_form_events(temp_file)
        result_xml  = etree.tostring(result_tree) 

        par = etree.XMLParser(remove_blank_text = True)
        clean_tree   = etree.XML(string_1_xml, parser = par)
        clean_result = etree.XML(result_xml, parser = par)

        self.assertEqual(etree.tostring(clean_tree), etree.tostring(clean_result))
        os.remove(temp_file)
Example #8
0
    def test_create_empty_event_tree_for_study_for_one_subjects(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.one_subject = """<?xml version='1.0' encoding='US-ASCII'?>
            <study>
            <subject>
            <NAME>TestSubject</NAME>
            <loinc_code>123456</loinc_code>
            <RESULT>123</RESULT>
            <REFERENCE_LOW>12.3</REFERENCE_LOW>
            <REFERENCE_HIGH>12.3</REFERENCE_HIGH>
            <REFERENCE_UNIT>g/dL</REFERENCE_UNIT>
            <DATE_TIME_STAMP/>
            <STUDY_ID>123</STUDY_ID>
        <timestamp/><redcapFormName>cbc</redcapFormName><eventName/><formDateField>cbc_lbdtc</formDateField><formCompletedFieldName>cbc_complete</formCompletedFieldName><formImportedFieldName>cbc_nximport</formImportedFieldName><redcapFieldNameValue>hemo_lborres</redcapFieldNameValue><redcapFieldNameUnits>hemo_lborresu</redcapFieldNameUnits><redcapFieldNameStatus>hemo_lbstat</redcapFieldNameStatus></subject>
        </study>
            """
        self.data_one_subject = etree.ElementTree(
            etree.fromstring(self.one_subject))

        self.output_one_subject = """<person_form_event><person><study_id>123</study_id><all_form_events><form>
		<name>cbc</name>
		<event>
    		<name>1_arm_1</name>
		<field><name>lymce_lborres</name><value/></field><field><name>lymce_lborresu</name><value/></field><field><name>hemo_lborresu</name><value/></field><field><name>cbc_lbdtc</name><value/></field><field><name>cbc_nximport</name><value/></field><field><name>lymce_lbstat</name><value/></field><field><name>cbc_complete</name><value/></field><field><name>hemo_lbstat</name><value/></field><field><name>hemo_lborres</name><value/></field></event>
		
		
        </form>
        <form>
            <name>chemistry</name>
            <event>
		        <name>1_arm_1</name>
		    <field><name>k_lborres</name><value/></field><field><name>chem_lbdtc</name><value/></field><field><name>sodium_lborresu</name><value/></field><field><name>k_lbstat</name><value/></field><field><name>sodium_lbstat</name><value/></field><field><name>chem_nximport</name><value/></field><field><name>chemistry_complete</name><value/></field><field><name>k_lborresu</name><value/></field><field><name>sodium_lborres</name><value/></field></event>
		
		
        </form>

	    <form>
		    <name>inr</name>
		    <event>
		    <name>1_arm_1</name>
		    <field><name>inr_lbdtc</name><value/></field><field><name>inr_complete</name><value/></field><field><name>inr_nximport</name><value/></field></event>
		
	       </form>
	
        </all_form_events></person></person_form_event>
        """
        self.expect_one_subject = etree.tostring(
            etree.fromstring(self.output_one_subject))

        self.result = etree.tostring(
            redi.create_empty_event_tree_for_study(self.data_one_subject,
                                                   self.data_all_form_events))
        self.assertEqual(self.expect_one_subject, self.result)
Example #9
0
    def test_empty_event(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        logger.info("Running " + __name__ 
            + "#test_empty_event() using study_id: " + `self.CONST_STUDY_ID`)
        # Case 1 input string
        string_1_empty_event = """
<event>
</event>
"""
        out_dict_1 = {'study_id':self.CONST_STUDY_ID}
        etree_1 = etree.ElementTree(etree.fromstring(string_1_empty_event))
        self.assertRaises(Exception, redi_lib.create_import_data_json, out_dict_1, etree_1)
Example #10
0
  def test_update_status_field_value_when_one_subject_with_no_form(self):
    redi.configure_logging(proj_root+'log/redi.log')
    self.source = """<person_form_event>
          <person>
              <study_id>99</study_id>
              <all_form_events>
              </all_form_events>
          </person>
      </person_form_event>
      """

    self.source_tree = etree.ElementTree(etree.fromstring(self.source))

    self.input = """
    <rediFieldMap>
      <clinicalComponent>
          <redcapFormName>cbc</redcapFormName>
          <redcapFieldNameValue>wbc_lborres</redcapFieldNameValue>
          <redcapFieldNameUnits>wbc_lborresu</redcapFieldNameUnits>
          <redcapStatusFieldName>wbc_lbstat</redcapStatusFieldName>
          <redcapStatusFieldValue>NOT_DONE</redcapStatusFieldValue>
      </clinicalComponent>

      <clinicalComponent>
          <redcapFormName>cbc</redcapFormName>
          <redcapFieldNameValue>neut_lborres</redcapFieldNameValue>
          <redcapFieldNameUnits>neut_lborresu</redcapFieldNameUnits>
      </clinicalComponent>

      <clinicalComponent>
          <redcapFormName>inr</redcapFormName>
          <redcapFieldNameValue>inr_lborres</redcapFieldNameValue>
          <redcapStatusFieldName>inr_lbstat</redcapStatusFieldName>
          <redcapStatusFieldValue>NOT_DONE</redcapStatusFieldValue>
      </clinicalComponent>
      </rediFieldMap>
    """

    self.input_tree = etree.ElementTree(etree.fromstring(self.input))

    self.output = """<person_form_event>
          <person>
              <study_id>99</study_id>
              <all_form_events>
              </all_form_events>
          </person>
      </person_form_event>
    """
    self.expect = etree.tostring(etree.fromstring(self.output))
    redi.updateStatusFieldValueInPersonFormEventTree(self.source_tree, self.input_tree)
    result = etree.tostring(self.source_tree)
    self.assertEqual(self.expect, result)
Example #11
0
    def setUp(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.CONST_STUDY_ID = 73

        global logger
        logger = logging.getLogger('redi')
        logging.basicConfig(filename=proj_root + 'log/redi.log',
                            format='%(asctime)s - %(levelname)s - \
                        %(name)s - %(message)s',
                            datefmt='%m/%d/%Y %H:%M:%S',
                            filemode='w',
                            level=logging.DEBUG)
        return ()
Example #12
0
 def setUp(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.CONST_STUDY_ID = 73
      
     global logger
     logger = logging.getLogger('redi')
     logging.basicConfig(filename=proj_root+'log/redi.log',
                     format='%(asctime)s - %(levelname)s - \
                     %(name)s - %(message)s',
                     datefmt='%m/%d/%Y %H:%M:%S',
                     filemode='w',
                     level=logging.DEBUG)
     return()
Example #13
0
 def setUp(self):
     redi.configure_logging()
     self.test_form_data = {'cbc': 'cbc_complete', 'chemistry': 'chemistry_complete'}
     self.expect = """record,redcap_event_name,field_name,value\n001-0001,"3_arm_1",hemo_lborres,12.3\n001-0001,"3_arm_1",hemo_lborresu,"g/dL"\n001-0001,"3_arm_1",plat_lborres,92\n001-0001,"3_arm_1",plat_lborresu,"thou/cu mm"\n001-0001,"3_arm_1",neut_lborres,52.8\n001-0001,"3_arm_1",neut_lborresu,"%"\n001-0001,"3_arm_1",anc_lbstat,"NOT_DONE"\n001-0001,"3_arm_1",lym_lbstat,"NOT_DONE"\n001-0001,"3_arm_1",lymce_lbstat,"NOT_DONE"\n001-0001,"3_arm_1",wbc_lbstat,"NOT_DONE"\n001-0001,"3_arm_1",cbc_lbdtc,"1908-08-11"\n001-0001,"3_arm_1",cbc_complete,2\n001-0001,"3_arm_1",cbc_nximport,"Y"\n"""
     self.output_date_format = "%Y-%m-%d"
     self.test_xml = """<?xml version='1.0' encoding='US-ASCII'?>
     <study>
         <subject>
     <NAME>WHITE BLOOD CELL COUNT</NAME>
     <COMPONENT_ID>1577876</COMPONENT_ID>
     <ORD_VALUE>6.0</ORD_VALUE>
     <REFERENCE_LOW>4.0</REFERENCE_LOW>
     <REFERENCE_HIGH>10.0</REFERENCE_HIGH>
     <REFERENCE_UNIT>thou/cu mm</REFERENCE_UNIT>
     <SPECIMN_TAKEN_TIME>1908-08-11 10:05:00</SPECIMN_TAKEN_TIME>
     <STUDY_ID>001-0001</STUDY_ID>
 <timestamp>1908-08-11</timestamp><redcapFormName>cbc</redcapFormName><eventName>3_arm_1</eventName><formDateField>cbc_lbdtc</formDateField><formCompletedFieldName>cbc_complete</formCompletedFieldName><formImportedFieldName>cbc_nximport</formImportedFieldName><redcapFieldNameValue>wbc_lborres</redcapFieldNameValue><redcapFieldNameUnits>wbc_lborresu</redcapFieldNameUnits><redcapFieldNameStatus>wbc_lbstat</redcapFieldNameStatus></subject>
 <subject>
     <NAME>HEMOGLOBIN</NAME>
     <COMPONENT_ID>1534435</COMPONENT_ID>
     <ORD_VALUE>12.3</ORD_VALUE>
     <REFERENCE_LOW>12.0</REFERENCE_LOW>
     <REFERENCE_HIGH>16.0</REFERENCE_HIGH>
     <REFERENCE_UNIT>g/dL</REFERENCE_UNIT>
     <SPECIMN_TAKEN_TIME>1908-08-11 10:05:00</SPECIMN_TAKEN_TIME>
     <STUDY_ID>001-0001</STUDY_ID>
 <timestamp>1908-08-11</timestamp><redcapFormName>cbc</redcapFormName><eventName>3_arm_1</eventName><formDateField>cbc_lbdtc</formDateField><formCompletedFieldName>cbc_complete</formCompletedFieldName><formImportedFieldName>cbc_nximport</formImportedFieldName><redcapFieldNameValue>hemo_lborres</redcapFieldNameValue><redcapFieldNameUnits>hemo_lborresu</redcapFieldNameUnits><redcapFieldNameStatus>hemo_lbstat</redcapFieldNameStatus></subject>
 <subject>
     <NAME>PLATELET COUNT</NAME>
     <COMPONENT_ID>1009</COMPONENT_ID>
     <ORD_VALUE>92</ORD_VALUE>
     <REFERENCE_LOW>150</REFERENCE_LOW>
     <REFERENCE_HIGH>450</REFERENCE_HIGH>
     <REFERENCE_UNIT>thou/cu mm</REFERENCE_UNIT>
     <SPECIMN_TAKEN_TIME>1908-08-11 10:05:00</SPECIMN_TAKEN_TIME>
     <STUDY_ID>001-0001</STUDY_ID>
 <timestamp>1908-08-11</timestamp><redcapFormName>cbc</redcapFormName><eventName>3_arm_1</eventName><formDateField>cbc_lbdtc</formDateField><formCompletedFieldName>cbc_complete</formCompletedFieldName><formImportedFieldName>cbc_nximport</formImportedFieldName><redcapFieldNameValue>plat_lborres</redcapFieldNameValue><redcapFieldNameUnits>plat_lborresu</redcapFieldNameUnits><redcapFieldNameStatus>plat_lbstat</redcapFieldNameStatus></subject>
 <subject>
     <NAME>NEUTROPHILS RELATIVE PERCENT</NAME>
     <COMPONENT_ID>1539315</COMPONENT_ID>
     <ORD_VALUE>52.8</ORD_VALUE>
     <REFERENCE_LOW>40.0</REFERENCE_LOW>
     <REFERENCE_HIGH>80.0</REFERENCE_HIGH>
     <REFERENCE_UNIT>%</REFERENCE_UNIT>
     <SPECIMN_TAKEN_TIME>1908-08-11 10:05:00</SPECIMN_TAKEN_TIME>
     <STUDY_ID>001-0001</STUDY_ID>
 <timestamp>1908-08-11</timestamp><redcapFormName>cbc</redcapFormName><eventName>3_arm_1</eventName><formDateField>cbc_lbdtc</formDateField><formCompletedFieldName>cbc_complete</formCompletedFieldName><formImportedFieldName>cbc_nximport</formImportedFieldName><redcapFieldNameValue>neut_lborres</redcapFieldNameValue><redcapFieldNameUnits>neut_lborresu</redcapFieldNameUnits><redcapFieldNameStatus>neut_lbstat</redcapFieldNameStatus></subject>
     </study>
     """
     self.translationTableXml = '''<rediFieldMap>
Example #14
0
    def test_empty_event(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        logger.info("Running " + __name__ +
                    "#test_empty_event() using study_id: " +
                    ` self.CONST_STUDY_ID `)
        # Case 1 input string
        string_1_empty_event = """
<event>
</event>
"""
        out_dict_1 = {'study_id': self.CONST_STUDY_ID}
        etree_1 = etree.ElementTree(etree.fromstring(string_1_empty_event))
        self.assertRaises(Exception, redi_lib.create_import_data_json,
                          out_dict_1, etree_1)
Example #15
0
    def setUp(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY, False)
        self.form_event_tree = """<?xml version='1.0' encoding='US-ASCII'?>
        <redcapProject>
        <name>Project</name>
        <form>
		<name>cbc</name>
		<formDateField>cbc_lbdtc</formDateField>
		<formCompletedFieldName>cbc_complete</formCompletedFieldName>
		<formImportedFieldName>cbc_nximport</formImportedFieldName>
        <formCompletedFieldValue>2</formCompletedFieldValue>
        <formImportedFieldValue>Y</formImportedFieldValue>
		<event>
    		<name>1_arm_1</name>
		</event>
		
		
        </form>
        <form>
            <name>chemistry</name>
            <formDateField>chem_lbdtc</formDateField>
            <formCompletedFieldName>chemistry_complete</formCompletedFieldName>
            <formImportedFieldName>chem_nximport</formImportedFieldName>
            <formCompletedFieldValue>2</formCompletedFieldValue>
            <formImportedFieldValue>Y</formImportedFieldValue>
            <event>
		        <name>1_arm_1</name>
		    </event>
		
		
        </form>

	    <form>
		    <name>inr</name>
		    <formDateField>inr_lbdtc</formDateField>
		    <formCompletedFieldName>inr_complete</formCompletedFieldName>
		    <formImportedFieldName>inr_nximport</formImportedFieldName>
            <formCompletedFieldValue>2</formCompletedFieldValue>
            <formImportedFieldValue>Y</formImportedFieldValue>
		    <event>
		    <name>1_arm_1</name>
		    </event>
		
	       </form>
	
        </redcapProject>
        """
        self.data_form_event_tree = etree.ElementTree(etree.fromstring(self.form_event_tree))
        return()
    def test_create_empty_event_tree_for_study_for_one_subjects(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.one_subject = """<?xml version='1.0' encoding='US-ASCII'?>
            <study>
            <subject>
            <NAME>TestSubject</NAME>
            <loinc_code>123456</loinc_code>
            <RESULT>123</RESULT>
            <REFERENCE_LOW>12.3</REFERENCE_LOW>
            <REFERENCE_HIGH>12.3</REFERENCE_HIGH>
            <REFERENCE_UNIT>g/dL</REFERENCE_UNIT>
            <DATE_TIME_STAMP/>
            <STUDY_ID>123</STUDY_ID>
        <timestamp/><redcapFormName>cbc</redcapFormName><eventName/><formDateField>cbc_lbdtc</formDateField><formCompletedFieldName>cbc_complete</formCompletedFieldName><formImportedFieldName>cbc_nximport</formImportedFieldName><redcapFieldNameValue>hemo_lborres</redcapFieldNameValue><redcapFieldNameUnits>hemo_lborresu</redcapFieldNameUnits><redcapFieldNameStatus>hemo_lbstat</redcapFieldNameStatus></subject>
        </study>
            """
        self.data_one_subject= etree.ElementTree(etree.fromstring(self.one_subject))
        
        self.output_one_subject = """<person_form_event><person><study_id>123</study_id><all_form_events><form>
		<name>cbc</name>
		<event>
    		<name>1_arm_1</name>
		<field><name>lymce_lborres</name><value/></field><field><name>lymce_lborresu</name><value/></field><field><name>hemo_lborresu</name><value/></field><field><name>cbc_lbdtc</name><value/></field><field><name>cbc_nximport</name><value/></field><field><name>lymce_lbstat</name><value/></field><field><name>cbc_complete</name><value/></field><field><name>hemo_lbstat</name><value/></field><field><name>hemo_lborres</name><value/></field></event>
		
		
        </form>
        <form>
            <name>chemistry</name>
            <event>
		        <name>1_arm_1</name>
		    <field><name>k_lborres</name><value/></field><field><name>chem_lbdtc</name><value/></field><field><name>sodium_lborresu</name><value/></field><field><name>k_lbstat</name><value/></field><field><name>sodium_lbstat</name><value/></field><field><name>chem_nximport</name><value/></field><field><name>chemistry_complete</name><value/></field><field><name>k_lborresu</name><value/></field><field><name>sodium_lborres</name><value/></field></event>
		
		
        </form>

	    <form>
		    <name>inr</name>
		    <event>
		    <name>1_arm_1</name>
		    <field><name>inr_lbdtc</name><value/></field><field><name>inr_complete</name><value/></field><field><name>inr_nximport</name><value/></field></event>
		
	       </form>
	
        </all_form_events></person></person_form_event>
        """
        self.expect_one_subject = etree.tostring(etree.fromstring(self.output_one_subject))
        
        self.result = etree.tostring(redi.create_empty_event_tree_for_study(self.data_one_subject,self.data_all_form_events))
        self.assertEqual(self.expect_one_subject, self.result)
Example #17
0
    def test_log(self):
        import os.path
        file_name = self.file_name
        sys.path.append('log')
        # remove any existing log file in log/ folder

        #if os.path.isfile(file_name):
        #    with open(file_name):
                #print "here"
        #        os.remove(file_name)
                #print os.path.isfile(file_name)

        # call the configure logging function
        redi.configure_logging()
        #print os.path.isfile(file_name)
        # check if the file is created
        assert os.path.isfile(file_name) == True
        # remove the file created through testing
        os.remove(file_name)
Example #18
0
    def test_update_formdatefield(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        redi.update_formdatefield(self.data, self.form_events_tree)

	    # output raw file to check it
        #redi.write_element_tree_to_file(self.data, 'rawData.xml')

        # initialize a dictionary for the formdatefield
        # [key, value] = [formdatefield, filled or not?(0/1)]
        isFormDateFieldFilled = {}
        for subject in self.data.iter('subject'):
            form_date_field = subject.find('formDateField').text
            if not form_date_field:
                isFormDateFieldFilled[form_date_field] = 1
        status=1
        for key,value in isFormDateFieldFilled.items():
            if value != status:
                status = 0
                break
        self.assertEqual(status,1)
Example #19
0
    def test_log(self):
        import os.path
        file_name = self.file_name
        sys.path.append('log')
        # remove any existing log file in log/ folder

        #if os.path.isfile(file_name):
        #    with open(file_name):
        #print "here"
        #        os.remove(file_name)
        #print os.path.isfile(file_name)

        # call the configure logging function
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)

        #print 'checking if log file was created: ' + file_name
        # check if the file is created
        assert os.path.isfile(file_name) == True

        # remove the file created through testing
        os.remove(file_name)
Example #20
0
    def setUp(self):
        # initialize the data with element tree
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.test_xml = """<?xml version="1.0" encoding="utf8"?>
<study>
    <subject>
        <NAME>TSH REFLEX</NAME>
        <loinc_code>1552152</loinc_code>
        <RESULT>0.74</RESULT>
        <REFERENCE_LOW>0.27</REFERENCE_LOW>
        <REFERENCE_HIGH>4.20</REFERENCE_HIGH>
        <REFERENCE_UNIT>mIU/L</REFERENCE_UNIT>
        <DATE_TIME_STAMP>1903-11-27 15:13:00</DATE_TIME_STAMP>
        <STUDY_ID>59</STUDY_ID>
    </subject>
    <subject>
        <NAME>HEP C RNA, QUANT REAL-TIME</NAME>
        <loinc_code>740</loinc_code>
        <RESULT>5.8</RESULT>
        <REFERENCE_LOW></REFERENCE_LOW>
        <REFERENCE_HIGH></REFERENCE_HIGH>
        <REFERENCE_UNIT>log IU</REFERENCE_UNIT>
        <DATE_TIME_STAMP>1903-11-27 15:13:00</DATE_TIME_STAMP>
        <STUDY_ID>59</STUDY_ID>
    </subject>
    <subject>
        <NAME>HCV QUANTITATIVE INTERPRETATION</NAME>
        <loinc_code>1534483</loinc_code>
        <RESULT>Detected</RESULT>
        <REFERENCE_LOW></REFERENCE_LOW>
        <REFERENCE_HIGH></REFERENCE_HIGH>
        <REFERENCE_UNIT></REFERENCE_UNIT>
        <DATE_TIME_STAMP>1903-11-27 15:13:00</DATE_TIME_STAMP>
        <STUDY_ID>59</STUDY_ID>
    </subject>
    </study>"""
        self.data = etree.ElementTree(etree.fromstring(self.test_xml))
        self.input_date_format = "%Y-%m-%d %H:%M:%S"
        self.output_date_format = "%Y-%m-%d"
Example #21
0
    def setUp(self):
        # initialize the data with element tree
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.test_xml = """<?xml version="1.0" encoding="utf8"?>
<study>
    <subject>
        <NAME>TSH REFLEX</NAME>
        <loinc_code>1552152</loinc_code>
        <RESULT>0.74</RESULT>
        <REFERENCE_LOW>0.27</REFERENCE_LOW>
        <REFERENCE_HIGH>4.20</REFERENCE_HIGH>
        <REFERENCE_UNIT>mIU/L</REFERENCE_UNIT>
        <DATE_TIME_STAMP>1903-11-27 15:13:00</DATE_TIME_STAMP>
        <STUDY_ID>59</STUDY_ID>
    </subject>
    <subject>
        <NAME>HEP C RNA, QUANT REAL-TIME</NAME>
        <loinc_code>740</loinc_code>
        <RESULT>5.8</RESULT>
        <REFERENCE_LOW></REFERENCE_LOW>
        <REFERENCE_HIGH></REFERENCE_HIGH>
        <REFERENCE_UNIT>log IU</REFERENCE_UNIT>
        <DATE_TIME_STAMP>1903-11-27 15:13:00</DATE_TIME_STAMP>
        <STUDY_ID>59</STUDY_ID>
    </subject>
    <subject>
        <NAME>HCV QUANTITATIVE INTERPRETATION</NAME>
        <loinc_code>1534483</loinc_code>
        <RESULT>Detected</RESULT>
        <REFERENCE_LOW></REFERENCE_LOW>
        <REFERENCE_HIGH></REFERENCE_HIGH>
        <REFERENCE_UNIT></REFERENCE_UNIT>
        <DATE_TIME_STAMP>1903-11-27 15:13:00</DATE_TIME_STAMP>
        <STUDY_ID>59</STUDY_ID>
    </subject>
    </study>"""
        self.data = etree.ElementTree(etree.fromstring(self.test_xml))
        self.input_date_format = "%Y-%m-%d %H:%M:%S"
        self.output_date_format = "%Y-%m-%d"
Example #22
0
    def test_research_id_to_redcap_id_converter(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)

        class MockRedcapClient(RedcapClient):
            def __init__(self, context):
                self.__context = context

            def send_data_to_redcap(self, data, overwrite=False):
                raise NotImplementedError()

            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'):
                return self.__context.dummy_get_data_from_redcap(
                    records_to_fetch, events_to_fetch, fields_to_fetch,
                    forms_to_fetch, return_format)

        redi.research_id_to_redcap_id_converter(self.data,
                                                MockRedcapClient(self),
                                                self.research_id_to_redcap_id,
                                                self.configuration_directory)
        result = etree.tostring(self.data)
        self.assertEqual(self.expect, result)
 def setUp(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
Example #24
0
 def test_update_form_imported(self):
     redi.configure_logging()
     redi.update_form_imported_field(self.data, self.form_events_tree, 'undefined')
     result = etree.tostring(self.data)
     self.assertEqual(self.expect, result)
 def setUp(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
 def test_create_empty_events_for_one_subject_all_fields_input(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.result = etree.tostring(redi.create_empty_events_for_one_subject(self.data1_test1,self.data2_test1))
     self.result = ''.join(self.result.split())
     self.expect_test1 = ''.join(self.expect_test1.split())
     self.assertEqual(self.expect_test1, self.result)
Example #27
0
 def setUp(self):
     # configure logging
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     # start a server in seperate thread
     thread.start_new_thread(self.server_setup,())
Example #28
0
 def setUp(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.test_raw_xml = """<?xml version='1.0' encoding='US-ASCII'?>
 def test_create_empty_events_for_one_subject_no_fields_input(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.assertRaises(Exception,redi.create_empty_events_for_one_subject,self.data1_test2,self.data2_test2)
Example #30
0
 def setUp(self):
     # configure logging
     redi.configure_logging()
     # start a server in seperate thread
     thread.start_new_thread(self.server_setup,())
Example #31
0
    def setUp(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.test_report_params = {
            'project': 'hcvtarget-uf',
            'report_file_path': proj_root + 'config/report.xml',
            'redcap_uri': 'https://hostname.org'}

        self.test_report_data = {
            'total_subjects': 5,
            'form_details': {
                'Total_chemistry_Forms': 22,
                'Total_cbc_Forms': 53
            },
            'subject_details': {
                '60': {'cbc_Forms': 1, 'chemistry_Forms': 1},
                '61': {'cbc_Forms': 2, 'chemistry_Forms': 1},
                '63': {'cbc_Forms': 11, 'chemistry_Forms': 4},
                '59': {'cbc_Forms': 39, 'chemistry_Forms': 16}
            },
            'errors' : [],
        }
        self.specimen_taken_time_summary = {'total': 15, 'blank': 3}
        self.test_alert_summary = {
            'multiple_values_alert': [
                'This is multiple values alert 1',
                'This is multiple values alert 2',
                'This is multiple values alert 3'],
            'max_event_alert': [
                'This is max event alert 1',
                'This is max event alert 2',
                'This is max event alert 3']
        }
        self.expected_xml = '''
<report>
    <header>
        <project>hcvtarget-uf</project>
        <date>'''+time.strftime("%m/%d/%Y")+'''</date>
        <redcapServerAddress>https://hostname.org</redcapServerAddress>
    </header>
    <summary>
        <subjectCount>5</subjectCount>
        <forms>
            <form>
                <form_name>Total_cbc_Forms</form_name>
                <form_count>53</form_count>
            </form>
            <form>
                <form_name>Total_chemistry_Forms</form_name>
                <form_count>22</form_count>
            </form>
        </forms>
    </summary>
    <alerts>
        <tooManyForms>
        <eventAlert>
            <message>This is max event alert 1</message>
        </eventAlert>
        <eventAlert>
            <message>This is max event alert 2</message>
        </eventAlert>
        <eventAlert>
            <message>This is max event alert 3</message>
        </eventAlert>
        </tooManyForms>
        <tooManyValues>
            <valuesAlert>
                <message>This is multiple values alert 1</message>
            </valuesAlert>
            <valuesAlert>
                <message>This is multiple values alert 2</message>
            </valuesAlert>
            <valuesAlert><message>This is multiple values alert 3</message>
        </valuesAlert></tooManyValues>
    </alerts>
    <subjectsDetails>
        <Subject><ID>59</ID>
        <forms>
            <form>
                <form_name>cbc_Forms</form_name>
                <form_count>39</form_count>
            </form>
            <form>
                <form_name>chemistry_Forms</form_name>
                <form_count>16</form_count>
            </form>
        </forms>
        </Subject>
        <Subject>
            <ID>60</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>1</form_count></form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>1</form_count>
                </form>
            </forms>
        </Subject>
        <Subject><ID>61</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>2</form_count>
                </form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>1</form_count>
                </form>
            </forms>
        </Subject>
        <Subject>
            <ID>63</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>11</form_count>
                </form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>4</form_count>
                </form>
            </forms>
        </Subject>
    </subjectsDetails>
    <errors/>
    <summaryOfSpecimenTakenTimes>
        <total>15</total>
        <blank>3</blank>
        <percent>20.0</percent>
    </summaryOfSpecimenTakenTimes>
</report>'''

        self.schema_str = StringIO('''\
            <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="report">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="header">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="project"/>
              <xs:element type="xs:string" name="date"/>
              <xs:element type="xs:string" name="redcapServerAddress"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="summary">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="subjectCount"/>
              <xs:element name="forms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="form_name"/>
                          <xs:element type="xs:byte" name="form_count"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="alerts">
          <xs:complexType>

             <xs:sequence>
              <xs:element name="tooManyForms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="eventAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>

              <xs:element name="tooManyValues">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="valuesAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="subjectsDetails">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Subject" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:byte" name="ID"/>
                    <xs:element name="forms">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element type="xs:string" name="form_name"/>
                                <xs:element type="xs:byte" name="form_count"/>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="errors">
        </xs:element>
        <xs:element name="summaryOfSpecimenTakenTimes">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="total"/>
              <xs:element type="xs:byte" name="blank"/>
              <xs:element type="xs:float" name="percent"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>''')
        return
 def setUp(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.sampleData = """<rediFieldMap>
Example #33
0
  def test_update_status_field_value_when_one_subject_with_two_forms_with_one_event_in_each_form(self):
    redi.configure_logging(DEFAULT_DATA_DIRECTORY)
    self.source = """<person_form_event>
      <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/>
                      </field>
                  </event>
              </form>
          </all_form_events>
      </person>
      </person_form_event>
      """

    self.source_tree = etree.ElementTree(etree.fromstring(self.source))

    self.input = """
    <rediFieldMap>
      <clinicalComponent>
          <redcapFormName>cbc</redcapFormName>
          <redcapFieldNameValue>wbc_lborres</redcapFieldNameValue>
          <redcapFieldNameUnits>wbc_lborresu</redcapFieldNameUnits>
          <redcapStatusFieldName>wbc_lbstat</redcapStatusFieldName>
          <redcapStatusFieldValue>NOT_DONE</redcapStatusFieldValue>
      </clinicalComponent>

      <clinicalComponent>
          <redcapFormName>cbc</redcapFormName>
          <redcapFieldNameValue>neut_lborres</redcapFieldNameValue>
          <redcapFieldNameUnits>neut_lborresu</redcapFieldNameUnits>
      </clinicalComponent>

      <clinicalComponent>
          <redcapFormName>inr</redcapFormName>
          <redcapFieldNameValue>inr_lborres</redcapFieldNameValue>
          <redcapStatusFieldName>inr_lbstat</redcapStatusFieldName>
          <redcapStatusFieldValue>NOT_DONE</redcapStatusFieldValue>
      </clinicalComponent>
      </rediFieldMap>
    """

    self.input_tree = etree.ElementTree(etree.fromstring(self.input))

    self.output = """<person_form_event>
      <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_form_event>
    """
    self.expect = etree.tostring(etree.fromstring(self.output))
    redi.updateStatusFieldValueInPersonFormEventTree(self.source_tree, self.input_tree)
    result = etree.tostring(self.source_tree)
    self.assertEqual(self.expect, result)
Example #34
0
 def test_update_event_name(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     redi.update_event_name(self.data, self.form_events_tree, 'undefined')
     result = etree.tostring(self.data)
     self.assertEqual(self.expect, result)
    def setUp(self):
        redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.test_report_params = {
            "project": "hcvtarget-uf",
            "report_file_path": proj_root + "config/report.xml",
            "redcap_server": "https://hostname.org",
        }

        self.test_report_data = {
            "total_subjects": 5,
            "form_details": {"Total_chemistry_Forms": 22, "Total_cbc_Forms": 53},
            "subject_details": {
                "60": {"cbc_Forms": 1, "chemistry_Forms": 1},
                "61": {"cbc_Forms": 2, "chemistry_Forms": 1},
                "63": {"cbc_Forms": 11, "chemistry_Forms": 4},
                "59": {"cbc_Forms": 39, "chemistry_Forms": 16},
            },
            "errors": [],
        }
        self.specimen_taken_time_summary = {"total": 15, "blank": 3}
        self.test_alert_summary = {
            "multiple_values_alert": [
                "This is multiple values alert 1",
                "This is multiple values alert 2",
                "This is multiple values alert 3",
            ],
            "max_event_alert": ["This is max event alert 1", "This is max event alert 2", "This is max event alert 3"],
        }
        self.expected_xml = (
            """
<report>
    <header>
        <project>hcvtarget-uf</project>
        <date>"""
            + time.strftime("%m/%d/%Y")
            + """</date>
        <redcapServerAddress>https://hostname.org</redcapServerAddress>
    </header>
    <summary>
        <subjectCount>5</subjectCount>
        <forms>
            <form>
                <form_name>Total_cbc_Forms</form_name>
                <form_count>53</form_count>
            </form>
            <form>
                <form_name>Total_chemistry_Forms</form_name>
                <form_count>22</form_count>
            </form>
        </forms>
    </summary>
    <alerts>
        <tooManyForms>
        <eventAlert>
            <message>This is max event alert 1</message>
        </eventAlert>
        <eventAlert>
            <message>This is max event alert 2</message>
        </eventAlert>
        <eventAlert>
            <message>This is max event alert 3</message>
        </eventAlert>
        </tooManyForms>
        <tooManyValues>
            <valuesAlert>
                <message>This is multiple values alert 1</message>
            </valuesAlert>
            <valuesAlert>
                <message>This is multiple values alert 2</message>
            </valuesAlert>
            <valuesAlert><message>This is multiple values alert 3</message>
        </valuesAlert></tooManyValues>
    </alerts>
    <subjectsDetails>
        <Subject><ID>59</ID>
        <forms>
            <form>
                <form_name>cbc_Forms</form_name>
                <form_count>39</form_count>
            </form>
            <form>
                <form_name>chemistry_Forms</form_name>
                <form_count>16</form_count>
            </form>
        </forms>
        </Subject>
        <Subject>
            <ID>60</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>1</form_count></form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>1</form_count>
                </form>
            </forms>
        </Subject>
        <Subject><ID>61</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>2</form_count>
                </form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>1</form_count>
                </form>
            </forms>
        </Subject>
        <Subject>
            <ID>63</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>11</form_count>
                </form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>4</form_count>
                </form>
            </forms>
        </Subject>
    </subjectsDetails>
    <errors/>
    <summaryOfSpecimenTakenTimes>
        <total>15</total>
        <blank>3</blank>
        <percent>20.0</percent>
    </summaryOfSpecimenTakenTimes>
</report>"""
        )

        self.schema_str = StringIO(
            """\
       		<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="report">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="header">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="project"/>
              <xs:element type="xs:string" name="date"/>
              <xs:element type="xs:string" name="redcapServerAddress"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="summary">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="subjectCount"/>
              <xs:element name="forms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="form_name"/>
                          <xs:element type="xs:byte" name="form_count"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="alerts">
          <xs:complexType>

             <xs:sequence>
              <xs:element name="tooManyForms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="eventAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>

              <xs:element name="tooManyValues">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="valuesAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="subjectsDetails">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Subject" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:byte" name="ID"/>
                    <xs:element name="forms">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element type="xs:string" name="form_name"/>
                                <xs:element type="xs:byte" name="form_count"/>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="errors">
        </xs:element>
        <xs:element name="summaryOfSpecimenTakenTimes">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="total"/>
              <xs:element type="xs:byte" name="blank"/>
              <xs:element type="xs:float" name="percent"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>"""
        )
        return
    def setUp(self):
    	redi.configure_logging(DEFAULT_DATA_DIRECTORY)
        self.test_report_params = {'project': 'hcvtarget-uf',
        							'report_file_path': proj_root + 'config/report.xml',
        							'redcap_server': 'https://hostname.org'}

        self.test_report_data = {
            'total_subjects': 5,
            'form_details': {
                'Total_chemistry_Forms': 22,
        		'Total_cbc_Forms': 53
            },
        	'subject_details': {
                '60': {'cbc_Forms': 1, 'chemistry_Forms': 1},
                '61': {'cbc_Forms': 2, 'chemistry_Forms': 1},
                '63': {'cbc_Forms': 11, 'chemistry_Forms': 4},
                '59': {'cbc_Forms': 39, 'chemistry_Forms': 16}
            },
            'errors' : [],
        }
        self.specimen_taken_time_summary = {'total': 15, 'blank': 3}
        self.test_alert_summary = {
            'multiple_values_alert': [
                'This is multiple values alert 1',
                'This is multiple values alert 2',
                'This is multiple values alert 3'],
            'max_event_alert': [
                'This is max event alert 1',
                'This is max event alert 2',
                'This is max event alert 3']
        }
       	self.expected_xml = '''
<report>
    <header>
        <project>hcvtarget-uf</project>
        <date>'''+time.strftime("%m/%d/%Y")+'''</date>
        <redcapServerAddress>https://hostname.org</redcapServerAddress>
    </header>
    <summary>
        <subjectCount>5</subjectCount>
        <forms>
            <form>
                <form_name>Total_cbc_Forms</form_name>
                <form_count>53</form_count>
            </form>
            <form>
                <form_name>Total_chemistry_Forms</form_name>
                <form_count>22</form_count>
            </form>
        </forms>
    </summary>
    <alerts>
        <tooManyForms>
        <eventAlert>
            <message>This is max event alert 1</message>
        </eventAlert>
        <eventAlert>
            <message>This is max event alert 2</message>
        </eventAlert>
        <eventAlert>
            <message>This is max event alert 3</message>
        </eventAlert>
        </tooManyForms>
        <tooManyValues>
            <valuesAlert>
                <message>This is multiple values alert 1</message>
            </valuesAlert>
            <valuesAlert>
                <message>This is multiple values alert 2</message>
            </valuesAlert>
            <valuesAlert><message>This is multiple values alert 3</message>
        </valuesAlert></tooManyValues>
    </alerts>
    <subjectsDetails>
        <Subject><ID>59</ID>
        <forms>
            <form>
                <form_name>cbc_Forms</form_name>
                <form_count>39</form_count>
            </form>
            <form>
                <form_name>chemistry_Forms</form_name>
                <form_count>16</form_count>
            </form>
        </forms>
        </Subject>
        <Subject>
            <ID>60</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>1</form_count></form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>1</form_count>
                </form>
            </forms>
        </Subject>
        <Subject><ID>61</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>2</form_count>
                </form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>1</form_count>
                </form>
            </forms>
        </Subject>
        <Subject>
            <ID>63</ID>
            <forms>
                <form>
                    <form_name>cbc_Forms</form_name>
                    <form_count>11</form_count>
                </form>
                <form>
                    <form_name>chemistry_Forms</form_name>
                    <form_count>4</form_count>
                </form>
            </forms>
        </Subject>
    </subjectsDetails>
    <errors/>
    <summaryOfSpecimenTakenTimes>
        <total>15</total>
        <blank>3</blank>
        <percent>20.0</percent>
    </summaryOfSpecimenTakenTimes>
</report>'''

       	self.schema_str = StringIO('''\
       		<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="report">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="header">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="project"/>
              <xs:element type="xs:string" name="date"/>
              <xs:element type="xs:string" name="redcapServerAddress"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="summary">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="subjectCount"/>
              <xs:element name="forms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="form_name"/>
                          <xs:element type="xs:byte" name="form_count"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="alerts">
          <xs:complexType>

             <xs:sequence>
              <xs:element name="tooManyForms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="eventAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>

              <xs:element name="tooManyValues">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="valuesAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="subjectsDetails">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Subject" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:byte" name="ID"/>
                    <xs:element name="forms">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element type="xs:string" name="form_name"/>
                                <xs:element type="xs:byte" name="form_count"/>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="errors">
        </xs:element>
        <xs:element name="summaryOfSpecimenTakenTimes">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="total"/>
              <xs:element type="xs:byte" name="blank"/>
              <xs:element type="xs:float" name="percent"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>''')
        return
Example #37
0
 def setUp(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.test_raw_xml = """<?xml version='1.0' encoding='US-ASCII'?>
Example #38
0
 def test_update_event_name(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     redi.update_event_name(self.data, self.form_events_tree, 'undefined')
     result = etree.tostring(self.data)
     self.assertEqual(self.expect, result)
Example #39
0
 def setUp(self):
     redi.configure_logging()
     self.test_raw_xml = """<?xml version='1.0' encoding='US-ASCII'?>
Example #40
0
    def setUp(self):
    	redi.configure_logging()
        self.test_report_params = {'project': 'hcvtarget-uf', 
        							'report_file_path': proj_root + 'config/report.xml', 
        							'redcap_server': 'https://hostname.org'}

        self.test_report_data = {'total_subjects': 5, 
        						'cumulative_end_date': '1907-08-24', 
        						'total_unique_dates': 52, 
        						'cumulative_start_date': '1904-02-17', 
        						'Total_chemistry_Forms': 22, 
        						'subject_details': {'60': {'earliestdate': datetime.date(1905, 3, 9), 'latestdate': datetime.date(1905, 6, 4), 'cbc_Forms': 1, 'chemistry_Forms': 1, 'StudyPeriod': 270}, 
        											'61': {'earliestdate': datetime.date(1905, 3, 8), 'latestdate': datetime.date(1905, 2, 23), 'cbc_Forms': 2, 'chemistry_Forms': 1, 'StudyPeriod': 75}, 
        											'63': {'earliestdate': datetime.date(1905, 2, 20), 'latestdate': datetime.date(1905, 1, 28), 'cbc_Forms': 11, 'chemistry_Forms': 4, 'StudyPeriod': 92}, 
        											'59': {'earliestdate': datetime.date(1905, 1, 30), 'latestdate': datetime.date(1905, 6, 10), 'cbc_Forms': 39, 'chemistry_Forms': 16, 'StudyPeriod': 318}}, 
        						'Total_cbc_Forms': 53}
        self.test_alert_summary = {'multiple_values_alert': ['This is multiple values alert 1',
        													'This is multiple values alert 2',
        													'This is multiple values alert 3'], 
        							'max_event_alert': ['This is max event alert 1',
        												'This is max event alert 2',
        												'This is max event alert 3']}
        self.test_form_data = {'cbc': 'cbc_complete', 'chemistry': 'chemistry_complete'}
       	self.expected_xml = '''<report><header><project>hcvtarget-uf</project><date>'''+time.strftime("%m/%d/%Y")+'''</date><redcapServerAddress>https://hostname.org</redcapServerAddress></header><summary><subjectCount>5</subjectCount><forms><form><form_name>Total_cbc_Forms</form_name><form_count>53</form_count></form><form><form_name>Total_chemistry_Forms</form_name><form_count>22</form_count></form></forms><total_unique_dates>52</total_unique_dates><dates><earliestDate>1904-02-17</earliestDate><latestDate>1907-08-24</latestDate></dates></summary><alerts><tooManyForms><eventAlert><message>This is max event alert 1</message></eventAlert><eventAlert><message>This is max event alert 2</message></eventAlert><eventAlert><message>This is max event alert 3</message></eventAlert></tooManyForms><tooManyValues><valuesAlert><message>This is multiple values alert 1</message></valuesAlert><valuesAlert><message>This is multiple values alert 2</message></valuesAlert><valuesAlert><message>This is multiple values alert 3</message></valuesAlert></tooManyValues></alerts><subjectsDetails><Subject><ID>60</ID><forms><form><form_name>cbc_Forms</form_name><form_count>1</form_count></form><form><form_name>chemistry_Forms</form_name><form_count>1</form_count></form></forms><StudyPeriod>270</StudyPeriod><earliestdate>1905-03-09</earliestdate><latestdate>1905-06-04</latestdate></Subject><Subject><ID>61</ID><forms><form><form_name>cbc_Forms</form_name><form_count>2</form_count></form><form><form_name>chemistry_Forms</form_name><form_count>1</form_count></form></forms><StudyPeriod>75</StudyPeriod><earliestdate>1905-03-08</earliestdate><latestdate>1905-02-23</latestdate></Subject><Subject><ID>63</ID><forms><form><form_name>cbc_Forms</form_name><form_count>11</form_count></form><form><form_name>chemistry_Forms</form_name><form_count>4</form_count></form></forms><StudyPeriod>92</StudyPeriod><earliestdate>1905-02-20</earliestdate><latestdate>1905-01-28</latestdate></Subject><Subject><ID>59</ID><forms><form><form_name>cbc_Forms</form_name><form_count>39</form_count></form><form><form_name>chemistry_Forms</form_name><form_count>16</form_count></form></forms><StudyPeriod>318</StudyPeriod><earliestdate>1905-01-30</earliestdate><latestdate>1905-06-10</latestdate></Subject></subjectsDetails></report>'''
      
       	self.schema_str = StringIO('''\
       		<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="report">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="header">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="project"/>
              <xs:element type="xs:string" name="date"/>
              <xs:element type="xs:string" name="redcapServerAddress"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="summary">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:byte" name="subjectCount"/>
              <xs:element name="forms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="form_name"/>
                          <xs:element type="xs:byte" name="form_count"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element type="xs:byte" name="total_unique_dates"/>
              <xs:element name="dates">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:date" name="earliestDate"/>
                    <xs:element type="xs:date" name="latestDate"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="alerts">
          <xs:complexType>
            
             <xs:sequence>
              <xs:element name="tooManyForms">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="eventAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>

              <xs:element name="tooManyValues">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="valuesAlert" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="message"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="subjectsDetails">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Subject" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:byte" name="ID"/>
                    <xs:element name="forms">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="form" maxOccurs="unbounded" minOccurs="0">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element type="xs:string" name="form_name"/>
                                <xs:element type="xs:byte" name="form_count"/>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <xs:element type="xs:short" name="StudyPeriod"/>
                    <xs:element type="xs:date" name="earliestdate"/>
                    <xs:element type="xs:date" name="latestdate"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>''')
        return
 def test_create_empty_events_for_one_subject_no_fields_input(self):
     redi.configure_logging(DEFAULT_DATA_DIRECTORY)
     self.assertRaises(Exception, redi.create_empty_events_for_one_subject,
                       self.data1_test2, self.data2_test2)