# Path: nacc/redcap2nacc.py
# def check_blanks(packet: uds3_packet.Packet, options: argparse.Namespace) \
# def blank_warnings(warnings, fieldname, formid, value, length, rule):
# def check_characters(packet: uds3_packet.Packet) -> typing.List:
# def check_for_bad_characters(field: Field) -> typing.List:
# def check_redcap_event(options, record) -> bool:
# def check_single_select(packet: uds3_packet.Packet):
# def empty(field):
# def exclusive(packet, fields, value_to_check=1):
# def set_blanks_to_zero(packet):
#     def set_to_zero_if_blank(*field_names):
# def convert(fp, options, out=sys.stdout, err=sys.stderr):
# def parse_args(args=None):
# def main():
# 
# Path: nacc/ftld/ivp/builder.py
# def build_ftld_ivp_form(record: dict, err=sys.stderr):
#     ''' Converts REDCap CSV data into a packet (list of IVP Form objects) '''
#     packet = ftld_ivp_packet.Packet()
# 
#     # Set up the forms..........
# 
#     # This form cannot precede March 1, 2015.
#     if not (int(record['visityr']) > 2015) or \
#         (int(record['visityr']) == 2015 and int(record['visitmo']) > 3) or \
#             (int(record['visityr']) == 2015 and int(record['visitmo']) == 3
#                 and int(record['visitday']) >= 1):
#         raise ValueError('Form date cannot precede March 1, 2015.')
# 
#     add_z1x(record, packet)
#     # Forms B3F, B9F, C1F, C2F, C3F, E2F, and E3F are REQUIRED.
#     # Forms A3A, C4F, C5F, and C6F are OPTIONAL and must be specifically
#     # marked as present for nacculator to process them
#     if record['ivp_z1x_complete'] in ['1', '2']:
#         try:
#             if record['ftda3afs'] == '1':
#                 add_a3a(record, packet)
#         except KeyError:
#             pass
#         add_b3f(record, packet)
#         add_b9f(record, packet)
#         add_c1f(record, packet)
#         add_c2f(record, packet)
#         add_c3f(record, packet)
#         try:
#             if record['ftdc4fs'] == '1':
#                 add_c4f(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['ftdc5fs'] == '1':
#                 add_c5f(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['ftdc6fs'] == '1':
#                 add_c6f(record, packet)
#         except KeyError:
#             pass
#     else:
#         print("ptid " + str(record['ptid']) +
#               ": No Z1X form found.", file=err)
#     add_e2f(record, packet)
#     add_e3f(record, packet)
#     update_header(record, packet)
# 
#     return packet


import unittest
from nacc import redcap2nacc
from nacc.ftld.ivp.builder import build_ftld_ivp_form
                    " blank: 'Blank if Question 4b A4SUB = 0 (No)'."]
        self.assertEqual(warnings, expected)

    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'] = '2'
        record['ftdcppa'] = ''
        record['ftdpabvf'] = ''
        record['ftdppasl'] = '0'
        ipacket = build_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = ["FTDCPPAS in form B9F is '2' with length '1', but should"
                    " be blank: 'Blank if Question 1 FTDPPASL = 0 (No)'."]
        self.assertEqual(warnings, expected)

    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'

# Path: nacc/redcap2nacc.py
# def check_blanks(packet: uds3_packet.Packet, options: argparse.Namespace) \
# def blank_warnings(warnings, fieldname, formid, value, length, rule):
# def check_characters(packet: uds3_packet.Packet) -> typing.List:
# def check_for_bad_characters(field: Field) -> typing.List:
# def check_redcap_event(options, record) -> bool:
# def check_single_select(packet: uds3_packet.Packet):
# def empty(field):
# def exclusive(packet, fields, value_to_check=1):
# def set_blanks_to_zero(packet):
#     def set_to_zero_if_blank(*field_names):
# def convert(fp, options, out=sys.stdout, err=sys.stderr):
# def parse_args(args=None):
# def main():
# 
# Path: nacc/ftld/ivp/builder.py
# def build_ftld_ivp_form(record: dict, err=sys.stderr):
#     ''' Converts REDCap CSV data into a packet (list of IVP Form objects) '''
#     packet = ftld_ivp_packet.Packet()
# 
#     # Set up the forms..........
# 
#     # This form cannot precede March 1, 2015.
#     if not (int(record['visityr']) > 2015) or \
#         (int(record['visityr']) == 2015 and int(record['visitmo']) > 3) or \
#             (int(record['visityr']) == 2015 and int(record['visitmo']) == 3
#                 and int(record['visitday']) >= 1):
#         raise ValueError('Form date cannot precede March 1, 2015.')
# 
#     add_z1x(record, packet)
#     # Forms B3F, B9F, C1F, C2F, C3F, E2F, and E3F are REQUIRED.
#     # Forms A3A, C4F, C5F, and C6F are OPTIONAL and must be specifically
#     # marked as present for nacculator to process them
#     if record['ivp_z1x_complete'] in ['1', '2']:
#         try:
#             if record['ftda3afs'] == '1':
#                 add_a3a(record, packet)
#         except KeyError:
#             pass
#         add_b3f(record, packet)
#         add_b9f(record, packet)
#         add_c1f(record, packet)
#         add_c2f(record, packet)
#         add_c3f(record, packet)
#         try:
#             if record['ftdc4fs'] == '1':
#                 add_c4f(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['ftdc5fs'] == '1':
#                 add_c5f(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['ftdc6fs'] == '1':
#                 add_c6f(record, packet)
#         except KeyError:
#             pass
#     else:
#         print("ptid " + str(record['ptid']) +
#               ": No Z1X form found.", file=err)
#     add_e2f(record, packet)
#     add_e3f(record, packet)
#     update_header(record, packet)
# 
#     return packet


# Path: tests/test_ftld_blanks.py
import unittest
from nacc import redcap2nacc
from nacc.ftld.ivp.builder import build_ftld_ivp_form

                    " blank: 'Blank if Question 4b A4SUB = 0 (No)'."]
        self.assertEqual(warnings, expected)

    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'] = '2'
        record['ftdcppa'] = ''
        record['ftdpabvf'] = ''
        record['ftdppasl'] = '0'
        ipacket = build_ftld_ivp_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(ipacket, self.options)
        expected = ["FTDCPPAS in form B9F is '2' with length '1', but should"
                    " be blank: 'Blank if Question 1 FTDPPASL = 0 (No)'."]
        self.assertEqual(warnings, expected)

    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_ftld_ivp_form(record)