# Path: nacc/redcap2nacc.py
# def check_redcap_event(options, record) -> bool:
#     """
#     Determines if the record's redcap_event_name and filled forms match the
#     options flag
#     """
#     if options.lbd and options.ivp:
#         event_name = 'initial'
#         try:
#             form_match_lbd = record['lbd_ivp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_ivp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.lbd and options.fvp:
#         event_name = 'follow'
#         try:
#             form_match_lbd = record['lbd_fvp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_fvp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.lbdsv and options.ivp:
#         event_name = 'initial'
#         try:
#             form_match_lbd = record['lbd_ivp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_ivp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.lbdsv and options.fvp:
#         event_name = 'follow'
#         try:
#             form_match_lbd = record['lbd_fvp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_fvp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.ftld and options.ivp:
#         event_name = 'initial'
#         form_match_ftld = record['ftld_present']
#         if form_match_ftld in ['0', '']:
#             return False
#     elif options.ftld and options.fvp:
#         event_name = 'follow'
#         form_match_ftld = record['fu_ftld_present']
#         if form_match_ftld in ['0', '']:
#             return False
#     elif options.ivp:
#         event_name = 'initial'
#         try:
#             form_match_z1 = record['ivp_z1_complete']
#         except KeyError:
#             form_match_z1 = ''
#             record['ivp_z1_complete'] = ''
#         form_match_z1x = record['ivp_z1x_complete']
#         if form_match_z1 in ['0', ''] and form_match_z1x in ['0', '']:
#             return False
#     elif options.fvp:
#         event_name = 'follow'
#         try:
#             form_match_z1 = record['fvp_z1_complete']
#         except KeyError:
#             form_match_z1 = ''
#             record['ivp_z1_complete'] = ''
#         form_match_z1x = record['fvp_z1x_complete']
#         if form_match_z1 in ['0', ''] and form_match_z1x in ['0', '']:
#             return False
#     # TODO: add -csf option if/when it is added to the full ADRC project.
#     elif options.cv:
#         event_name = 'covid'
#     elif options.np:
#         event_name = 'neuropath'
#     elif options.tfp:
#         event_name = 'follow'
#         try:
#             followup_match = record['tvp_z1x_checklist_complete']
#             if followup_match in ['', '0']:
#                 return False
#         except KeyError:
#             try:
#                 followup_match = record['tfp_z1x_complete']
#                 if followup_match in ['', '0']:
#                     return False
#             except KeyError:
#                 try:
#                     followup_match = record['tele_z1x_complete']
#                     if followup_match in ['', '0']:
#                         return False
#                 except KeyError:
#                     print("Could not find a REDCap field for TFP Z1X form.")
#                     return False
#     elif options.tfp3:
#         event_name = 'tele'
#     elif options.m:
#         event_name = 'milestone'
# 
#     redcap_event = record['redcap_event_name']
#     event_match = event_name in redcap_event
#     return event_match


import unittest
from nacc.redcap2nacc import check_redcap_event
    def test_for_ivp(self):
        '''
        Checks that the -ivp flag with no other options returns the correct
        visit (not LBD IVP or FTLD IVP).
        '''
        self.options.ivp = True
        record = {'redcap_event_name': 'initial_visit_year_arm_1',
                  'ivp_z1_complete': '', 'ivp_z1x_complete': '2'}
        result = check_redcap_event(self.options, record)
        self.assertTrue(result)

    def test_for_not_ivp(self):
        '''
        Checks that the initial_visit is not returned when the -ivp flag is not
        set.
        '''
        self.options.fvp = True
        record = {'redcap_event_name': 'initial_visit_year_arm_1',
                  'fvp_z1_complete': '', 'fvp_z1x_complete': ''}
        result = check_redcap_event(self.options, record)
        self.assertFalse(result)

    def test_for_multiple_flags(self):
        '''
        Checks that options like -lbd -ivp are functional.
        '''
        self.options.ivp = True
        self.options.lbd = True
        record = {'redcap_event_name': 'initial_visit_year_arm_1',
                  'lbd_ivp_b1l_complete': '2'}

# Path: nacc/redcap2nacc.py
# def check_redcap_event(options, record) -> bool:
#     """
#     Determines if the record's redcap_event_name and filled forms match the
#     options flag
#     """
#     if options.lbd and options.ivp:
#         event_name = 'initial'
#         try:
#             form_match_lbd = record['lbd_ivp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_ivp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.lbd and options.fvp:
#         event_name = 'follow'
#         try:
#             form_match_lbd = record['lbd_fvp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_fvp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.lbdsv and options.ivp:
#         event_name = 'initial'
#         try:
#             form_match_lbd = record['lbd_ivp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_ivp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.lbdsv and options.fvp:
#         event_name = 'follow'
#         try:
#             form_match_lbd = record['lbd_fvp_b1l_complete']
#         except KeyError:
#             form_match_lbd = record['lbd_fvp_b1l_clinical_symptoms_and_exam_complete']
#         if form_match_lbd in ['0', '']:
#             return False
#     elif options.ftld and options.ivp:
#         event_name = 'initial'
#         form_match_ftld = record['ftld_present']
#         if form_match_ftld in ['0', '']:
#             return False
#     elif options.ftld and options.fvp:
#         event_name = 'follow'
#         form_match_ftld = record['fu_ftld_present']
#         if form_match_ftld in ['0', '']:
#             return False
#     elif options.ivp:
#         event_name = 'initial'
#         try:
#             form_match_z1 = record['ivp_z1_complete']
#         except KeyError:
#             form_match_z1 = ''
#             record['ivp_z1_complete'] = ''
#         form_match_z1x = record['ivp_z1x_complete']
#         if form_match_z1 in ['0', ''] and form_match_z1x in ['0', '']:
#             return False
#     elif options.fvp:
#         event_name = 'follow'
#         try:
#             form_match_z1 = record['fvp_z1_complete']
#         except KeyError:
#             form_match_z1 = ''
#             record['ivp_z1_complete'] = ''
#         form_match_z1x = record['fvp_z1x_complete']
#         if form_match_z1 in ['0', ''] and form_match_z1x in ['0', '']:
#             return False
#     # TODO: add -csf option if/when it is added to the full ADRC project.
#     elif options.cv:
#         event_name = 'covid'
#     elif options.np:
#         event_name = 'neuropath'
#     elif options.tfp:
#         event_name = 'follow'
#         try:
#             followup_match = record['tvp_z1x_checklist_complete']
#             if followup_match in ['', '0']:
#                 return False
#         except KeyError:
#             try:
#                 followup_match = record['tfp_z1x_complete']
#                 if followup_match in ['', '0']:
#                     return False
#             except KeyError:
#                 try:
#                     followup_match = record['tele_z1x_complete']
#                     if followup_match in ['', '0']:
#                         return False
#                 except KeyError:
#                     print("Could not find a REDCap field for TFP Z1X form.")
#                     return False
#     elif options.tfp3:
#         event_name = 'tele'
#     elif options.m:
#         event_name = 'milestone'
# 
#     redcap_event = record['redcap_event_name']
#     event_match = event_name in redcap_event
#     return event_match


# Path: tests/test_check_redcap_event.py
import unittest
from nacc.redcap2nacc import check_redcap_event

    def test_for_ivp(self):
        '''
        Checks that the -ivp flag with no other options returns the correct
        visit (not LBD IVP or FTLD IVP).
        '''
        self.options.ivp = True
        record = {'redcap_event_name': 'initial_visit_year_arm_1',
                  'ivp_z1_complete': '', 'ivp_z1x_complete': '2'}
        result = check_redcap_event(self.options, record)
        self.assertTrue(result)

    def test_for_not_ivp(self):
        '''
        Checks that the initial_visit is not returned when the -ivp flag is not
        set.
        '''
        self.options.fvp = True
        record = {'redcap_event_name': 'initial_visit_year_arm_1',
                  'fvp_z1_complete': '', 'fvp_z1x_complete': ''}
        result = check_redcap_event(self.options, record)
        self.assertFalse(result)

    def test_for_multiple_flags(self):
        '''
        Checks that options like -lbd -ivp are functional.
        '''
        self.options.ivp = True
        self.options.lbd = True
        record = {'redcap_event_name': 'initial_visit_year_arm_1',
                  'lbd_ivp_b1l_complete': '2'}

        result = check_redcap_event(self.options, record)