Esempio n. 1
0
    def test_for_FTDPABVF_blank(self):
        record = make_filled_form()
        record['ftdpabvf'] = '9'
        record['ftdbvft'] = ''
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = [
            "'FTDPABVF' is '9' with length '1', but should be blank:"
            " 'Blank if Question 22 FTDBVFT = blank'."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 2
0
    def test_for_filled_when_ruled_blank(self):
        # Have it look for the langa4 error to see that general blanking rules
        # are working (langa4 also comes before the variable (a4sub)
        # it's dependent on)
        record = make_filled_form()
        record['a4sub'] = '0'
        record['langa4'] = '1'
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = [
            "'LANGA4' is '1' with length '1', but should be blank:"
            " 'Blank if Question 4b A4SUB = 0 (No)'."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 3
0
    def test_for_special_case_FTDCPC2F(self):
        '''
        One packet of questions should be left blank if FTDCPC2F has a value
        (anything between 95-98)
        '''
        record = make_filled_form()
        record['ftdcpc2f'] = '95'
        record['ftdhaird'] = '1'
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = [
            "'FTDhAIRD' is '1' with length '1', but should be blank:"
            " 'Blank if Question 0 FTDCPC2F = 95'."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 4
0
    def test_for_FTDPABVF_0(self):
        '''
        Have it make sure _blanking_rule_for_others_left_blank is working by
        checking both 0 and False instances (it will skip if either of these
        is the case for two questions)
        '''
        record = make_filled_form()
        record['ftdpabvf'] = '9'
        record['ftdcppa'] = '0'
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = [
            "'FTDPABVF' is '9' with length '1', but should be blank:"
            " 'Blank if Question 12 FTDCPPA = 0 (No) '."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 5
0
    def test_for_single_blanking_rule_returned(self):
        '''
        Have it make sure that only one error is returned from a list of
        rules when not working with special cases (special cases need a
        fix in a later feature branch)
        '''
        record = make_filled_form()
        record['ftdcppas'] = '******'
        record['ftdcppa'] = ''
        record['ftdpabvf'] = ''
        record['ftdppasl'] = '0'
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = [
            "'FTDCPPAS' is '2' with length '1', but should be blank:"
            " 'Blank if Question 1 FTDPPASL = 0 (No)'."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 6
0
    def test_for_special_case_or2(self):
        '''
        Have it make sure _blanking_rule_ftld_or2 works properly (and by
        extension or3, or4, and or5) - This blanking rule depends on either
        of two possible answers to questions, along with regular
        blanking rules
        '''
        record = make_filled_form()
        record['ftdmrirf'] = '0'
        record['ftdmrifa'] = '9'
        record['ftdmriob'] = ''
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = [
            "'FTDMRIRF' is '0' with length '1', but should be blank: "
            "'Blank if Question 2a, FTDMRIFA, = 0 (No) or 9"
            " (Unknown)'."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 7
0
    def test_for_special_case_FTDMRIOS(self):
        '''
        Have it make sure _blanking_rule_ftld_or2a works properly -
        This blanking rule has an extra condition added to the or2 rules
        (packet['FTDMRIOB'] != 1)
        '''
        record = make_filled_form()
        record['ftdmrios'] = '1'
        record['ftdmriob'] = '0'
        ipacket = build_uds3_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        # FTDMRIOS is a Char field with a length of 60 characters
        expected = [
            "'FTDMRIOS' is"
            " '1                                                  "
            "         ' with length '60', but should be blank:"
            " 'Blank if Question 2a11 FTDMRIOB ne 1 (Yes)'."
        ]
        self.assertEqual(warnings, expected)
Esempio n. 8
0
def convert(fp, options, out=sys.stdout, err=sys.stderr):
    """Converts data in REDCap's CSV format to NACC's fixed-width format."""
    reader = csv.DictReader(fp)
    for record in reader:
        # Right now the csf form is a single non-longitudinal form in a
        # separate REDCap project with no redcap_event_name.
        if not options.csf:
            event_match = check_redcap_event(options, record)
            if not event_match:
                continue

        print("[START] ptid : " + str(record['ptid']), file=err)
        try:
            if options.lbd and options.ivp:
                packet = lbd_ivp_builder.build_uds3_lbd_ivp_form(record)
            elif options.lbd and options.fvp:
                packet = lbd_fvp_builder.build_uds3_lbd_fvp_form(record)
            elif options.ftld and options.ivp:
                packet = ftld_ivp_builder.build_uds3_ftld_ivp_form(record)
            elif options.ftld and options.fvp:
                packet = ftld_fvp_builder.build_uds3_ftld_fvp_form(record)
            elif options.csf:
                packet = csf_builder.build_uds3_csf_form(record)
            elif options.ivp:
                packet = ivp_builder.build_uds3_ivp_form(record)
            elif options.np:
                packet = np_builder.build_uds3_np_form(record)
            elif options.fvp:
                packet = fvp_builder.build_uds3_fvp_form(record)
            elif options.tfp:
                packet = tfp_builder.build_uds3_tfp_form(record)
            elif options.m:
                packet = m_builder.build_uds3_m_form(record)

        except Exception:
            if 'ptid' in record:
                print("[SKIP] Error for ptid : " + str(record['ptid']),
                      file=err)
            traceback.print_exc()
            continue

        if not options.np and not options.m and not options.tfp and not \
                options.lbd and not options.ftld and not options.csf:
            set_blanks_to_zero(packet)

        if options.m:
            blanks_uds3.set_zeros_to_blanks(packet)

        warnings = []
        try:
            warnings += check_blanks(packet, options)
        except KeyError:
            print("[SKIP] Error for ptid : " + str(record['ptid']), file=err)
            traceback.print_exc()
            continue

        try:
            warnings += check_characters(packet)
            if warnings:
                print("[SKIP] Error for ptid : " + str(record['ptid']),
                      file=err)
                warn = "\n".join(map(str, warnings))
                warn = warn.replace("\\", "")
                print(warn, file=err)
                continue
        except KeyError:
            print("[SKIP] Error for ptid : " + str(record['ptid']), file=err)
            traceback.print_exc()
            continue

        if not options.np and not options.m and not options.lbd and not \
                options.ftld and not options.csf:
            warnings += check_single_select(packet)

        for form in packet:

            try:
                print(form, file=out)
            except AssertionError:
                print("[SKIP] Error for ptid : " + str(record['ptid']),
                      file=err)
                traceback.print_exc()
                continue