def create_subject_identifier():
    """Create subject_identifier for screening EIT"""
    start = 1003
    end = 1103
    #protocol = "074"
    protocol = "S"
    clinician = 1
    number = "100000"

    check = CheckDigit()

    while clinician < 10:
        data.append([])
        data.append(
            ["Subject identifiers for clinician {}0".format(clinician)])
        number = str(long(number) + start)
        for _ in range(start, end + 1):
            #seq = protocol+number
            seq = number
            check_digit = check.calculate(int(seq), modulus=97)
            identifier = protocol + "-" + number[:2] + "-" + number[
                2:] + "-" + str(check_digit)
            data.append([identifier])
            print identifier
            number = str(long(number) + 1)

        clinician += 1
        number = str(clinician) + "00001"
    def post_save_register_infants(self, created, **kwargs):
        """Registers infant(s) using the bhp_identifier class which allocates identifiers and creates registered_subject instances.

        Called on the post_save signal"""
        protocol="074"
        i_indicator = "1"
        check = CheckDigit()
        consent = MaternalConsent.objects.get(subject_identifier=self.registered_subject.subject_identifier)
        if created:
            seq = consent.subject_identifier[6:-4]
            check_digit = check.calculate(int(protocol+str(seq)+i_indicator), modulus=7)
            if consent.cohort=='antepartum':
                prefix = 'A'
            elif consent.cohort=='peripartum':
                prefix = "P"
            else:
                prefix = "C"
            new_identifier = protocol+"-"+prefix+"-"+str(seq)+"-"+i_indicator+"-"+str(check_digit)

            RegisteredSubject.objects.create(
                subject_identifier=new_identifier,
                registration_datetime=datetime.now(),
                subject_type='infant',
                user_created=self.user_created,
                created=datetime.now(),
                first_name='',
                initials='',
                registration_status='registered',
                relative_identifier=self.registered_subject.subject_identifier,
                study_site=consent.study_site)

        return new_identifier
    def sbid_check(self):
        from edc.core.identifier.classes import CheckDigit

        maternal_subject = MaternalConsent.objects.get(registered_subject__subject_identifier=self.cleaned_data.get('registered_subject').relative_identifier)
        if maternal_subject.cohort != 'control':
            check = CheckDigit()
            screen_id = self.cleaned_data.get('infant_redcap_sbid')
            seq = int(screen_id[2:-8]+screen_id[-7:-3])
            check_digit = check.calculate(seq, modulus=97)
            if str(check_digit) != screen_id[-2:]:
                return True
        return False
def check_invalid_screening_bids():
    mod = CheckDigit()
    data.append([])
    data.append(['Incorrect Screening BIDS'])
    #file = open('screen_bids.txt', 'r')
    file = open(os.path.join(Path(os.path.dirname(os.path.realpath(__file__))).ancestor(2).child('etc'), 'screen_bids.txt'), 'r')
    subject_identifiers = file.readlines()

    for bid in subject_identifiers:
        bid = bid.strip()
        check_digit = mod.calculate(int(bid[2:4]+bid[5:9]), modulus=97)
        if str(check_digit) != bid[-2:]:
            print ("Error: {} Is not a valid BID check digit should be {}\n".format(bid, check_digit))
            data.append([bid])
Example #5
0
    def save_new_consent(self, using=None, subject_identifier=None):
        from edc.core.identifier.models import SubjectIdentifier
        from edc.core.identifier.classes import CheckDigit

        check = CheckDigit()
        protocol = '074'
        m_indicator = "2"
        prefix = 'M'

        if self.cohort=='antepartum':
            cohort_id=10
            prev_id = SubjectIdentifier.objects.filter(device_id=cohort_id).order_by('-sequence_number')
            if prev_id:
                seq = prev_id[0].sequence_number+1
            else:
                seq = 101
        elif self.cohort=='peripartum':
            cohort_id=20
            prev_id = SubjectIdentifier.objects.filter(device_id=cohort_id).order_by('-sequence_number')
            if prev_id:
                seq = prev_id[0].sequence_number+1
            else:
                seq = 201
        else:
            prefix='C'
            cohort_id=30
            prev_id = SubjectIdentifier.objects.filter(device_id=cohort_id).order_by('-sequence_number')
            if prev_id:
                seq = prev_id[0].sequence_number+1
            else:
                seq = 301
        check_digit = check.calculate(int(protocol+str(seq)+m_indicator), modulus=7)
        subject_identifier = protocol+"-"+prefix+"-"+str(seq)+"-"+m_indicator+"-"+str(check_digit)
        identifier = SubjectIdentifier(padding=3, sequence_number=seq, identifier=subject_identifier, device_id=cohort_id,sequence_model_name='maternalconsent', sequence_app_label='eit_maternal')
        identifier.save(bypass=True)
        return subject_identifier
def check_invalid_enrolled_bids():
    mod = CheckDigit()
    data.append([])
    data.append(['Incorrect Enrolled BIDS'])
    #file = open('enroll_bids.txt', 'r')
    file = open(os.path.join(Path(os.path.dirname(os.path.realpath(__file__))).ancestor(2).child('etc'), 'enroll_bids.txt'), 'r')
    subject_identifiers = file.readlines()
    enrolled_bids = []
    
    registered_subject = RegisteredSubject.objects.all()
    for subject in registered_subject:
        enrolled_bids.append(subject.subject_identifier)

    for bid in subject_identifiers:
        bid = bid.strip()
        if bid not in enrolled_bids:
            print ("Error: {} is not a valid BID".format(bid))
            data.append([bid])