# Path: nacc/uds3/m/builder.py
# def build_uds3_m_form(record):
# def update_header(record, packet):
# def parse_date(date, DMY_choice):
# def subject_deceased(status):
# def subject_discont(status):
# 
# Path: nacc/uds3/blanks.py
# def convert_rule_to_python(name: str, rule: str) -> bool:
# def extract_blanks(csvfile):
# def _blanking_rule_check_single_value(key, eq, value):
#     def should_be_blank(packet):
# def _blanking_rule_check_within_range(key, eq, start, stop):
#     def should_be_blank(packet):
# def _blanking_rule_dummy():
# def _blanking_rule_ftldsubt():
# def _blanking_rule_learned():
# def _blanking_rule_telmile():
# def set_zeros_to_blanks(packet):
#     def set_to_blank_if_zero(*field_names):
# def main():
# 
# Path: nacc/uds3/packet.py
# class Packet(list):
#     def __init__(self):
#     def __getitem__(self, key):
# 
# Path: nacc/uds3/m/forms.py
# CURRENT_YEAR = date.today().year
# def header_fields():  # may not need the headers.
#     def __init__(self):
# class FormM(nacc.uds3.FieldBag):


import unittest
from nacc.uds3.m import builder as m_builder
from nacc.uds3 import blanks
from nacc.uds3 import packet as m_packet
from nacc.uds3.m import forms as m_form
        m.CHANGEMO = '02'
        m.CHANGEDY = '28'
        m.CHANGEYR = '2015'
        m.PROTOCOL = '2'
        m.ACONSENT = '0'
        m.RECOGIM = '0'
        m.REPHYILL = '0'
        m.REREFUSE = '0'
        m.RENAVAIL = '0'
        m.RENURSE = '0'
        m.REJOIN = '0'
        m.FTLDDISC = '0'
        m.FTLDREAS = '1'
        m.FTLDREAX = ''  # a char field
        m.DISCONT = '0'
        packet.append(m)
        blanks.set_zeros_to_blanks(packet)

        self.assertEqual(packet['RENURSE'], '')
        self.assertEqual(packet['RECOGIM'], '')
        self.assertEqual(packet['REPHYILL'], '')
        self.assertEqual(packet['REREFUSE'], '')
        self.assertEqual(packet['RENAVAIL'], '')
        self.assertEqual(packet['FTLDDISC'], '')
        self.assertEqual(packet['AUTOPSY'], '')
        self.assertEqual(packet['FTLDREAX'], '')

    # Some of these fields cannot be 0 (outside of inclusive_range), so this will test for the fields that are marked "1" for a ticked checkbox and "0" if left blank in REDCap. The others will correctly be caught as a regular violated blanking rule, since they must be filled by hand
    def test_m1_blank_if_discont(self):
        ''' If discontinued should be blank '''

# Path: nacc/uds3/m/builder.py
# def build_uds3_m_form(record):
# def update_header(record, packet):
# def parse_date(date, DMY_choice):
# def subject_deceased(status):
# def subject_discont(status):
# 
# Path: nacc/uds3/blanks.py
# def convert_rule_to_python(name: str, rule: str) -> bool:
# def extract_blanks(csvfile):
# def _blanking_rule_check_single_value(key, eq, value):
#     def should_be_blank(packet):
# def _blanking_rule_check_within_range(key, eq, start, stop):
#     def should_be_blank(packet):
# def _blanking_rule_dummy():
# def _blanking_rule_ftldsubt():
# def _blanking_rule_learned():
# def _blanking_rule_telmile():
# def set_zeros_to_blanks(packet):
#     def set_to_blank_if_zero(*field_names):
# def main():
# 
# Path: nacc/uds3/packet.py
# class Packet(list):
#     def __init__(self):
#     def __getitem__(self, key):
# 
# Path: nacc/uds3/m/forms.py
# CURRENT_YEAR = date.today().year
# def header_fields():  # may not need the headers.
#     def __init__(self):
# class FormM(nacc.uds3.FieldBag):


# Path: tests/test_m1.py
import unittest
from nacc.uds3.m import builder as m_builder
from nacc.uds3 import blanks
from nacc.uds3 import packet as m_packet
from nacc.uds3.m import forms as m_form

        m.CHANGEMO = '02'
        m.CHANGEDY = '28'
        m.CHANGEYR = '2015'
        m.PROTOCOL = '2'
        m.ACONSENT = '0'
        m.RECOGIM = '0'
        m.REPHYILL = '0'
        m.REREFUSE = '0'
        m.RENAVAIL = '0'
        m.RENURSE = '0'
        m.REJOIN = '0'
        m.FTLDDISC = '0'
        m.FTLDREAS = '1'
        m.FTLDREAX = ''  # a char field
        m.DISCONT = '0'
        packet.append(m)
        blanks.set_zeros_to_blanks(packet)

        self.assertEqual(packet['RENURSE'], '')
        self.assertEqual(packet['RECOGIM'], '')
        self.assertEqual(packet['REPHYILL'], '')
        self.assertEqual(packet['REREFUSE'], '')
        self.assertEqual(packet['RENAVAIL'], '')
        self.assertEqual(packet['FTLDDISC'], '')
        self.assertEqual(packet['AUTOPSY'], '')
        self.assertEqual(packet['FTLDREAX'], '')

    # Some of these fields cannot be 0 (outside of inclusive_range), so this will test for the fields that are marked "1" for a ticked checkbox and "0" if left blank in REDCap. The others will correctly be caught as a regular violated blanking rule, since they must be filled by hand
    def test_m1_blank_if_discont(self):
        ''' If discontinued should be blank '''

        packet = m_packet.Packet()