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 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])
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])