def validate_child_birth(individual_data, family_data):
    """US08 -- Children should be born after marriage of parents (and not more than 9 months after their divorce)"""
    marr_error_entries = dict()
    div_error_entries = dict()
    for fid, family in family_data.items():
        children_list = list(family.chil)
        if len(children_list) > 0 and (children_list != ['N', 'A']):
            for child in children_list:
                for uid, individual in individual_data.items():
                    if uid == child:
                        if check_two_dates(individual.birt, family.marr):
                            marr_error_entries[fid] = uid
                        elif family.div != 'NA':
                            if validate_date_format(family.div):
                                fam_div_date = convert_str_to_date(family.div)

                            if validate_date_format(individual.birt):
                                indi_birth_date = convert_str_to_date(
                                    individual.birt)

                            if abs((fam_div_date + relativedelta(month=9)) -
                                   indi_birth_date).days > 270:
                                div_error_entries[fid] = uid

    return marr_error_entries, div_error_entries
def validate_childBirth_with_parentsDeath(individual_data, family_data):
    """US09 -- Child should be born before death of mother and before nine months after death of father"""
    child_mother_error = dict()
    child_father_error = dict()
    for fid, family in family_data.items():
        children_list = list(family.chil)
        if len(children_list) > 0 and (children_list != ['N', 'A']):
            for child in children_list:
                fam_obj = family_data[family.fid]
                if individual_data[fam_obj.wife_id].deat != 'NA':
                    if check_two_dates(individual_data[fam_obj.wife_id].deat,
                                       individual_data[child].birt):
                        child_mother_error[fid] = [child, fam_obj.wife_id]

                if individual_data[fam_obj.husb_id].deat != 'NA':
                    if validate_date_format(
                            individual_data[fam_obj.husb_id].deat):
                        father_death_date = convert_str_to_date(
                            individual_data[fam_obj.husb_id].deat)

                    if validate_date_format(individual_data[child].birt):
                        child_birth_date = convert_str_to_date(
                            individual_data[child].birt)

                    if ((father_death_date + relativedelta(months=+9)) -
                            child_birth_date).days < 0:
                        child_father_error[fid] = [child, fam_obj.husb_id]

    return child_mother_error, child_father_error
Esempio n. 3
0
    def set_birthdate(self, date):
        """Sets the birthdate for an individual, it call valid_date_format from helperFunctions to ensure birthday is in right format"""

        if validate_date_format(self.birt):
            self.birt = date
        else:
            raise ValueError('Invalid date!')
def is_anniversary_in_next_thirty_days(date):
    """ Check for a date to see if happening within the next 30 days
        must pass a date in the format of yyyy-mm-dd
        Function returns: True or False
    """
    if validate_date_format(date):
        new_date = change_date_format(date)
        values = new_date.split('-')

        val = ((datetime.now().year - int(values[0])) + int(values[0]))
        compare_date = "{0}-{1}-{2}".format(str(val), values[1], values[2])

    if str(datetime.now().date()) <= compare_date < str(datetime.now().date() +
                                                        timedelta(days=30)):
        return True
    return False
Esempio n. 5
0
    def get_age(self):
        """US27 - Individual Age. Returns the age of the individual"""
        if validate_date_format(self.birt):
            birth_year, birth_month, birth_day = change_date_format(
                self.birt).split('-')

            if self.alive:
                provided_date = datetime.today().date()
                age = (provided_date.year - int(birth_year) -
                       ((datetime.today().month, datetime.today().day) <
                        (int(birth_month), int(birth_day))))
            else:
                death_year, death_month, death_day = change_date_format(
                    self.deat).split('-')
                age = (int(death_year) - int(birth_year) -
                       ((int(death_month), int(death_day)) <
                        (int(birth_month), int(birth_day))))

        return age
    def test_validate_date_format(self):
        """Unit test for Validating date format function"""

        self.assertEqual(validate_date_format('7 MAY 2018'), True, True)
        self.assertNotEqual(validate_date_format('8/FEB/2018'), True, False)
        self.assertNotEqual(validate_date_format('8/FEB/18'), True, False)