def test_three_colors(self): styles.full_border(self.test_sheet, 'O2:P3', rgb_hex=['aa00ff', '00aaff', 'aaaa00'])
def test_four_colors(self): styles.full_border(self.test_sheet, 'O5:P6', rgb_hex=['aa00ff', '00aaff', 'aaaa00', 'ffaa88'])
def test_four_border_styles_and_color(self): styles.full_border(self.test_sheet, 'L11:M12', border=['dashDot', 'dotted', 'hair', 'thick', 'double'], rgb_hex=['aa00ff', '00aaff', 'aaaa00', 'ffaa88'])
def test_two_colors(self): styles.full_border(self.test_sheet, 'L14:M15', rgb_hex=['aa00ff', '00aaff'])
def test_one_cell_border(self): """ Testing a one cell border :return: """ styles.full_border(self.test_sheet, 'B4')
def test_four_border_styles(self): styles.full_border(self.test_sheet, 'L8:M9', border=['dashDot', 'dotted', 'hair', 'thick'])
def test_color_border(self): """ Testing the rgb_hex parameter by passing in a RGB string :return: """ styles.full_border(self.test_sheet, 'G12:J18', rgb_hex=['aaaaff'])
def create_door_label(no_print=False): """ Takes the fs_Res and fs_Con reports from eCase, and prints a formatted Door Label to place on the front of the resident’s room """ try: sheet_book = Workbook() door_sheet = sheet_book.active if os.path.isfile(rf'{constants.DOWNLOADS_DIR}\p_name.txt'): p_file = open(rf'{constants.DOWNLOADS_DIR}\p_name.txt') p_name = p_file.read() p_file.close() else: p_name = '' with open(rf'{constants.DOWNLOADS_DIR}\fs_Res.csv', newline='') as basic_info: basic_info_data = csv.reader(basic_info, delimiter=',', quotechar='"') basic_data = list(basic_info_data) namecard_font = Font(size=36, bold=True, name='Arial') nhi_font = Font(size=28, bold=True, name='Copperplate Gothic Light') door_sheet['B6'] = basic_data[1][1] + ' ' + basic_data[1][ 3] + ' (' + p_name + ') ' + basic_data[1][2] door_sheet['B6'].font = namecard_font door_sheet['B6'].alignment = Alignment(horizontal='center', vertical='center', wrap_text=True) door_sheet.merge_cells(start_row=6, start_column=2, end_row=18, end_column=10) door_sheet['C24'] = basic_data[1][2] door_sheet['C24'].font = nhi_font door_sheet['C27'] = basic_data[1][1] door_sheet['C27'].font = nhi_font door_sheet['C29'] = basic_data[1][3] door_sheet['C29'].font = nhi_font door_sheet['C35'] = 'NHI No:' door_sheet['C35'].font = nhi_font door_sheet['F35'] = basic_data[1][10] door_sheet['F35'].font = nhi_font # # # Inserting Resident Photo for file in os.listdir(rf'{constants.DOWNLOADS_DIR}'): if re.match(r"^[A-Z]{3}[0-9]{4} Photo\.", file): photoname = file profile = Image(rf'{constants.DOWNLOADS_DIR}\{photoname}') profile.anchor = 'H21' profile.height = 212 profile.width = 192 door_sheet.add_image(profile) sheet_book.save(rf'{constants.OUTPUTS_DIR}\door_label.xlsx') styles.full_border(door_sheet, 'B6:J18', border=['double']) styles.full_border(door_sheet, 'B21:J38', border=['double']) door_sheet.print_area = 'A5:K39' styles.print_settings(door_sheet, landscape=False) sheet_book.save(rf'{constants.OUTPUTS_DIR}\door_label.xlsx') sheet_book.close() if not no_print: os.startfile(rf'{constants.OUTPUTS_DIR}\door_label.xlsx', 'print') info_files_remover() except PermissionError: info_files_remover() return button_functions.popup_error( "Could not print Door Label, as" " the file has been opened by someone")
def test_lower_case_cell_range(self): """ Testing a cell range that was given in lowercase :return: """ styles.full_border(self.test_sheet, 'i2:j7')
def test_alternate_border(self): """ Testing the border parameter by giving a 'double' linetype :return: """ styles.full_border(self.test_sheet, 'D12:E18', border=['double'])
def test_rectangle_full_border(self): """ Testing a rectangular border :return: """ styles.full_border(self.test_sheet, 'D9:J10')
def test_square_full_border(self): """ Testing a square border :return: """ styles.full_border(self.test_sheet, 'D4:G7')
def test_one_column_full_border(self): """ Testing a one column border :return: """ styles.full_border(self.test_sheet, 'B6:B12')
def test_no_values(self): styles.full_border(self.test_sheet, 'O8:P9', border=[], rgb_hex=[])
def test_two_border_styles(self): styles.full_border(self.test_sheet, 'L2:M3', border=['double', 'thin'])
def create_front_sheet(village=False, no_print=False, nurses=False): """ Takes the fs_Res and fs_Con reports from eCase, and produces a formatted front sheet for use in admission files. Prints out 2 copies with banking account information, and 1 without for the admission filing. This is for the Admission officer and accountants """ sheet_book = Workbook() front_sheet = sheet_book.active basic_info_index = [ 'D6', 'D8', 'D9', 'D10', 'D12', 'D13', 'D14', 'D15', 'D16', 'I10', 'I13', 'I14', 'I15', 'I16' ] epoa_info_index = [ 'D21', 'D23', 'D24', 'D25', 'D26', 'I21', 'I23', 'I24', 'I25', 'I26' ] contact_info_index = [ 'D31', 'D33', 'D35', 'D36', 'D37', 'D40', 'D41', 'D42', 'D43', 'I31', 'I33', 'I35', 'I36', 'I37', 'I40', 'I41', 'I42', 'I43' ] funeral_info_index = [ 'D47', 'D48', 'I47', 'D51', 'D53', 'D54', 'D55', 'D57', 'D58', 'D59', 'D60', 'I51', 'I53', 'I54', 'I55', 'I57', 'I58', 'I59', 'I60' ] # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # headings main_heading_font = Font(size=14, bold=True, italic=True, color='000080') headings_font = Font(size=10, bold=True, italic=True, color='008000') sheet_titles_font = Font(size=10, bold=True, underline='single') sheet_headings = { 'RESIDENTS INFORMATION FRONT SHEET': 'B4', 'ENDURING POWER OF ATTORNEY DETAILS': 'B19', 'CONTACTS FOR HEALTH AND WELFARE DECISIONS': 'B29', 'FUNERAL DIRECTOR': 'B46' } sheet_titles = { 'Health and Welfare': 'B20', 'Property': 'G20', 'First Contact': 'B30', 'Second Contact': 'G30', 'Send Monthly SAV Account to': 'B50', 'Send Monthly Trust Account to': 'G50' } basic_info_fields = { 'Location at SAV': 'B6', 'Title': 'B8', 'Surname': 'B9', 'Forenames': 'B10', 'Preferred Name': 'B11', 'Date of Birth': 'B12', 'Place of Birth': 'B13', 'Religion': 'B14', 'Gender': 'B15', 'Marital Status': 'B16', 'Doctor at SAV': 'G10', 'Telephone No.': 'G11', 'NHI No': 'G13', 'Date Admitted': 'G14', 'Care Level': 'G15', 'Ethnic Group': 'G16' } # This is for two contacts epoa_info_fields = { 'B21': 'Name', 'B23': 'Home Phone', 'B24': 'Work Phone', 'B25': 'Mobile Phone', 'B26': 'E-mail', 'G21': 'Name', 'G23': 'Home Phone', 'G24': 'Work Phone', 'G25': 'Mobile Phone', 'G26': 'E-mail' } # This is for the Primary and secondary contacts contact_info_fields = { 'B31': 'Name', 'B33': 'Relationship', 'B35': 'Address', 'B40': 'Home Phone', 'B41': 'Work Phone', 'B42': 'Mobile Phone', 'B43': 'E-mail', 'G31': 'Name', 'G33': 'Relationship', 'G35': 'Address', 'G40': 'Home Phone', 'G41': 'Work Phone', 'G42': 'Mobile Phone', 'G43': 'E-mail' } # Funeral Director. Additional Monthly SAV and Trust account contact funeral_info_fields = { 'B47': 'Company Name', 'B48': 'Phone Number', 'G47': 'Type of Service', 'B51': 'Name', 'B53': 'Address', 'B57': 'Home Phone', 'B58': 'Work Phone', 'B59': 'Mobile Phone', 'B60': 'E-mail', 'G51': 'Name', 'G53': 'Address', 'G57': 'Home Phone', 'G58': 'Work Phone', 'G59': 'Mobile Phone', 'G60': 'E-mail' } front_sheet['B1'].font = main_heading_font # sheet headings writing to sheet & setting text styles for heading in sheet_headings: front_sheet[sheet_headings[heading]] = heading front_sheet[sheet_headings[heading]].font = headings_font # sheet titles writing to sheet & setting text style for title in sheet_titles: front_sheet[sheet_titles[title]] = title front_sheet[sheet_titles[title]].font = sheet_titles_font # Writing the basic info headers into the file for info in basic_info_fields: front_sheet[basic_info_fields[info]] = info # EPOA Details writing to sheet for epoa in epoa_info_fields: front_sheet[epoa] = epoa_info_fields[epoa] # Contact info writing to sheet# # # for contact in contact_info_fields: front_sheet[contact] = contact_info_fields[contact] # Funeral director info writing to sheet for funeral_info in funeral_info_fields: front_sheet[funeral_info] = funeral_info_fields[funeral_info] # sheet image writing to sheet & positioning logo = Image( r'J:\Quality Data\Data Technician\eCase Migration\ecase_automated\images/SAVLandscape.png' ) logo.anchor = 'A1' logo.width = 250 logo.height = 40 front_sheet.add_image(logo) sheet_book.save(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx') # Setting text borders for whole sheet styles.full_border(front_sheet, 'D6') styles.full_border(front_sheet, 'D8:D11') styles.full_border(front_sheet, 'D12:D17') styles.full_border(front_sheet, 'I10:I11') styles.full_border(front_sheet, 'I13:I17') styles.full_border(front_sheet, 'D21') styles.full_border(front_sheet, 'D23:D26') styles.full_border(front_sheet, 'I21') styles.full_border(front_sheet, 'I23:I26') styles.full_border(front_sheet, 'D31') styles.full_border(front_sheet, 'D33') styles.full_border(front_sheet, 'D35:D38') styles.full_border(front_sheet, 'D40:D43') styles.full_border(front_sheet, 'I31') styles.full_border(front_sheet, 'I33') styles.full_border(front_sheet, 'I35:I38') styles.full_border(front_sheet, 'I40:I43') styles.full_border(front_sheet, 'D47:D48') styles.full_border(front_sheet, 'I47') styles.full_border(front_sheet, 'D51') styles.full_border(front_sheet, 'I51') styles.full_border(front_sheet, 'D53:D55') styles.full_border(front_sheet, 'I53:I55') styles.full_border(front_sheet, 'D57:D60') styles.full_border(front_sheet, 'I57:I60') # Column widths styles.print_settings( front_sheet, widths=[0.15, 17.0, .15, 23.0, 4.15, 4.15, 16.0, .15, 28.0], landscape=False) respite = False # Basic Resident info Writing to sheet# # # doctors = ['Mascher', 'Jun', 'Mulgan', 'Hulley'] if os.path.isfile(rf'{constants.DOWNLOADS_DIR}\p_name.txt'): p_file = open(rf'{constants.DOWNLOADS_DIR}\p_name.txt') p_name = p_file.read() p_file.close() else: p_name = '' front_sheet['D11'] = p_name with open(rf'{constants.DOWNLOADS_DIR}\fs_Res.csv', newline='') as basic_info: basic_info_data = csv.reader(basic_info, delimiter=',', quotechar='"') basic_data = list(basic_info_data) try: if 'Andrew' in basic_data[1][0]: basic_data[1][0] = basic_data[1][0][20:len(basic_data[1][0])] if not any(substring in basic_data[1][9] for substring in doctors): respite = True month = [ '0', 'Jan', 'Feb', 'Mar', 'Apri', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] for cell in basic_info_index: front_sheet[cell] = basic_data[1][basic_info_index.index(cell)] if cell == 'D12': front_sheet[cell] = ( f'{basic_data[1][4][8:10]}/' f'{month[int(basic_data[1][4][5:7])]}/' f'{basic_data[1][4][0:4]}') if cell == 'I14': front_sheet[cell] = ( f'{basic_data[1][11][8:10]}/' f'{month[int(basic_data[1][11][5:7])]}/' f'{basic_data[1][11][0:4]}') except IndexError: info_files_remover() return button_functions.popup_error( "9002: NHI is incorrect, please check you've entered it correctly " "and the resident is set up correctly with that NHI") except ValueError: #if date is empty front_sheet[cell] = "Not Available" pass for file in os.listdir(rf'{constants.DOWNLOADS_DIR}'): if re.match(r"^[A-Z]{3}[0-9]{4} Photo\.", file): photoname = file profile = Image(rf'{constants.DOWNLOADS_DIR}\{photoname}') profile.anchor = 'I2' profile.height = 140 profile.width = 100 front_sheet.add_image(profile) sheet_book.save(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx') with open(rf'{constants.DOWNLOADS_DIR}\fs_Con.csv', newline='') as contact_info: contact_info_data = csv.reader(contact_info, delimiter=',', quotechar='"') contact_data = list(contact_info_data) for row in contact_data[1:len(contact_data)]: if row[9] == 'First Contact': for cell in contact_info_index[0:9]: front_sheet[cell] = row[contact_info_index.index(cell)] elif row[9] == 'Second Contact': for cell in contact_info_index[9:18]: front_sheet[cell] = row[contact_info_index.index(cell) - 9] elif row[9] == 'EPA Welfare': front_sheet[epoa_info_index[0]] = row[0] front_sheet[epoa_info_index[1]] = row[5] front_sheet[epoa_info_index[2]] = row[6] front_sheet[epoa_info_index[3]] = row[7] front_sheet[epoa_info_index[4]] = row[8] elif row[9] == 'EPA Property': front_sheet[epoa_info_index[5]] = row[0] front_sheet[epoa_info_index[6]] = row[5] front_sheet[epoa_info_index[7]] = row[6] front_sheet[epoa_info_index[8]] = row[7] front_sheet[epoa_info_index[9]] = row[8] elif row[9] == 'Funeral Director': front_sheet[funeral_info_index[0]] = row[0] front_sheet[funeral_info_index[1]] = row[6] elif row[9] == 'Send Fees Account' or row[9] == 'Billing': front_sheet[funeral_info_index[3]] = row[0] front_sheet[funeral_info_index[4]] = row[2] front_sheet[funeral_info_index[5]] = row[3] front_sheet[funeral_info_index[6]] = row[4] front_sheet[funeral_info_index[7]] = row[5] front_sheet[funeral_info_index[8]] = row[6] front_sheet[funeral_info_index[9]] = row[7] front_sheet[funeral_info_index[10]] = row[8] elif row[9] == 'Send Trust Account' or row[9] == 'Guaranator': front_sheet[funeral_info_index[11]] = row[0] front_sheet[funeral_info_index[12]] = row[2] front_sheet[funeral_info_index[13]] = row[3] front_sheet[funeral_info_index[14]] = row[4] front_sheet[funeral_info_index[15]] = row[5] front_sheet[funeral_info_index[16]] = row[6] front_sheet[funeral_info_index[17]] = row[7] front_sheet[funeral_info_index[18]] = row[8] elif row[9] == 'Resident': front_sheet['B17'] = 'Email' front_sheet['D17'] = row[8] front_sheet['G17'] = 'Contact Number' front_sheet['I17'] = row[5] # Doctors numbers. SAV Drs dont want them on the front sheet anymore if respite: if row[9] == 'Medical Practitioner': if row[7] != '': front_sheet['I11'] = row[7] elif row[6] != '': front_sheet['I11'] = row[6] elif row[5] != '': front_sheet['I11'] = row[5] else: front_sheet['I11'] = 'No Number Present' try: # Printing out Frontsheet without monthly accounts fields # For Everyone front_sheet.print_area = 'B1:I48' sheet_book.save(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx') if not no_print: os.startfile(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx', 'print') # Second info copy just for village nurses if nurses: os.startfile(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx', 'print') # Printing out Frontsheet with monthly accounts fields # For Admissions and Village manager front_sheet.print_area = 'B1:I60' sheet_book.save(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx') if not no_print: if not nurses: os.startfile(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx', 'print') # Just for admissions if not no_print: if not village and not nurses: # print an extra accounts page if in the MCF os.startfile(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx', 'print') sheet_book.save(rf'{constants.OUTPUTS_DIR}\front_sheet.xlsx') sheet_book.close() info_files_remover() except PermissionError: info_files_remover() return button_functions.popup_error( "Could not print front sheets, as" " the file has been opened by someone")
def test_three_border_styles(self): styles.full_border(self.test_sheet, 'L5:M6', border=['double', 'thin', 'thick'])
def village_birthdays(only_village=False, current=False): """ Creates a formatted excel document of all Village residents with a birthday this month """ birthdays_raw = [] birthdays_file = Workbook() birthdays_sheet = birthdays_file.active current_date = datetime.now() widths = [5.6, 23, 23, 26, 12, 10, 10, 11.5, 4.5, 4.5, 8, 5] headers = [ 'Title', 'FirstName', 'LastName', 'Wing', 'Block', 'Unit', 'Room', 'dateOfBirth', 'Age', 'Day', 'Month', 'Year' ] styles.print_settings(birthdays_sheet, widths=widths, header=headers) if current_date.month == 12: c_month = 1 c_year = current_date.year + 1 else: c_month = current_date.month + 1 c_year = current_date.year if current: if c_month == 1: c_month = 12 c_year = c_year - 1 else: c_month = c_month - 1 with open(rf'{constants.DOWNLOADS_DIR}\birthdayList_MCF.csv' ) as birthdays_info: birthdays_data = csv.reader(birthdays_info, delimiter=',', quotechar='"') for row in birthdays_data: try: month = int(str.split(row[7], sep='-')[1]) day = int(str.split(row[7], sep='-')[2]) year = int(str.split(row[7], sep='-')[0]) new_age = c_year - year if month >= c_month: if month < (c_month + 1): birthdays_raw.append([row, day, month, year, new_age]) elif c_month == 12: if month == 1 or month == 2: birthdays_raw.append([row, day, month, year, new_age]) elif c_month == 11: if month == 1: birthdays_raw.append([row, day, month, year, new_age]) except IndexError: pass for row in birthdays_raw: birthdays_sheet.append([ row[0][0], row[0][1], row[0][2], row[0][3], row[0][4], row[0][5], row[0][6], row[0][7], row[4], row[1], row[2], row[3] ]) birthdays_file.save( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Residentbirthdays.xlsx') birthdays_file.close() xl = pd.ExcelFile( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Residentbirthdays.xlsx') df = xl.parse('Sheet') df = df.sort_values(by=['Month', 'Day']) writer = pd.ExcelWriter( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Residentbirthdays.xlsx') df.to_excel(writer, sheet_name='Sheet', columns=[ 'Title', 'FirstName', 'LastName', 'Wing', 'Block', 'Unit', 'Room', 'dateOfBirth', 'Age', 'Day', 'Month', 'Year' ], index=False) writer.save() writer.close() if only_village is False: os.startfile( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Residentbirthdays.xlsx' ) os.remove(rf'{constants.DOWNLOADS_DIR}\birthdayList_MCF.csv') # This continues the generation, and produces a file with only village # birthdays, formatted for use by Liz Keene else: xl = pd.ExcelFile( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Residentbirthdays.xlsx' ) df = xl.parse('Sheet') df = df.sort_values(by=['Block', 'Month', 'Day']) del df['Wing'] del df['Room'] df.dropna(axis=0, how='any', inplace=True) df = df[df.Block != 'Unknown'] df = df[df.Block != ''] writer = pd.ExcelWriter( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Villagerawbirthdays.xlsx' ) df.to_excel(writer, sheet_name='Sheet', columns=[ 'Title', 'FirstName', 'LastName', 'Block', 'Unit', 'dateOfBirth', 'Age', 'Day', 'Month', 'Year' ], index=False) writer.save() writer.close() title = 'Resident birthdays' subtitle = 'Best Wishes from' subtitle2 = 'The Retirement Living Team!' date = datetime(c_year, c_month, 1).strftime("%B") + ' ' + str(c_year) birthdays_file = load_workbook( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Villagerawbirthdays.xlsx' ) birthday_sheet = birthdays_file.active village_birthdays_file = Workbook() resident_birthdays = village_birthdays_file.active title_font = Font(size=26, bold=True, name='Arial', color='703010') resident_birthdays['F2'] = title resident_birthdays['F3'] = date resident_birthdays['C46'] = subtitle resident_birthdays['C47'] = subtitle2 resident_birthdays['F2'].font = title_font resident_birthdays['F2'].alignment = Alignment(horizontal='right', vertical='center') resident_birthdays['F3'].font = title_font resident_birthdays['F3'].alignment = Alignment(horizontal='right', vertical='center') resident_birthdays['C46'].alignment = Alignment(horizontal='center', vertical='center') resident_birthdays['C47'].alignment = Alignment(horizontal='center', vertical='center') # skip first 7 rows rowcount = 7 alpha = [] for letter in range(65, 91): alpha.append(chr(letter)) for row in birthday_sheet.iter_rows(min_row=2): rowcount += 1 count = 1 month = datetime(row[9].value, row[8].value, row[7].value).strftime("%B") data = [ row[1].value + ' ' + row[2].value, '', str(row[3].value) + ' ' + str(row[4].value), str(row[7].value) + ' ' + month, ' ', row[6].value ] for element in data: resident_birthdays[f'{alpha[count]}{rowcount}'] = element count += 1 styles.full_border(resident_birthdays, 'A2:F49', border=['thick']) styles.full_border(resident_birthdays, f'B8:E{rowcount}') resident_birthdays.print_area = "A2:F49" widths = [5.6, 27.5, 5.6, 16.9, 13, 10.5, 9.2] styles.print_settings(resident_birthdays, widths) village_birthdays_file.save( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\VillageBirthdays-{date}.xlsx' ) village_birthdays_file.close() cakeimg = Image( rf'J:\Quality Data\Data Technician\eCase Migration\ecase_automated\images\birthdaycake.jpg' ) cakeimg.height = 100 cakeimg.width = 100 messageimg = Image( rf'J:\Quality Data\Data Technician\eCase Migration\ecase_automated\images\birthdayimage.jpg' ) messageimg.height = 100 messageimg.width = 200 village_birthdays_file = load_workbook( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\VillageBirthdays-{date}.xlsx' ) resident_birthdays = village_birthdays_file.active resident_birthdays.add_image(messageimg, 'B2') village_birthdays_file.save( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Villagebirthdays-{date}.xlsx' ) resident_birthdays.add_image(cakeimg, 'C41') village_birthdays_file.save( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\VillageBirthdays-{date}.xlsx' ) village_birthdays_file.close() os.startfile( rf'{constants.OUTPUTS_DIR}\Resident Birthdays\Villagebirthdays-{date}.xlsx' ) os.remove(rf'{constants.DOWNLOADS_DIR}\birthdayList_MCF.csv')
def test_one_row_full_border(self): """ Testing a one row border :return: """ styles.full_border(self.test_sheet, 'B2:G2')