diff --git a/compare_eRegister_vs_hie_data.py b/compare_eRegister_vs_hie_data.py index fc85299..46ea6f7 100644 --- a/compare_eRegister_vs_hie_data.py +++ b/compare_eRegister_vs_hie_data.py @@ -7,6 +7,7 @@ from dateutil.relativedelta import relativedelta from dateutil.rrule import * +import os # Open the spreadsheet def compare_eregister_vs_hie_data(demographics_file, hie_file,facility_name): @@ -18,10 +19,14 @@ def compare_eregister_vs_hie_data(demographics_file, hie_file,facility_name): sheet2 = workbook2.worksheets[0] # Create a list to store the values - + wb2 = Workbook() # set file path filepath2="/home/openmrs/openmrs-openshr-utils/data/"+facility_name+"_found_HTS_observations.xlsx" + + if os.path.exists(filepath2): + os.remove(filepath2) + # save workbook wb2.save(filepath2) wb2 = load_workbook(filepath2) @@ -41,6 +46,9 @@ def compare_eregister_vs_hie_data(demographics_file, hie_file,facility_name): file_date=(start_date + relativedelta(weekday=FR(-1))).strftime('%d_%m_%Y') filepath3="/home/openmrs/openmrs-openshr-utils/data/"+facility_name+"_missing_HTS_observations_"+file_date+".xlsx" + if os.path.exists(filepath3): + os.remove(filepath3) + # save workbook wb3.save(filepath3) wb3 = load_workbook(filepath3) diff --git a/convert_demographics_excel_to_csv.py b/convert_demographics_excel_to_csv.py index 3b947c5..1624191 100644 --- a/convert_demographics_excel_to_csv.py +++ b/convert_demographics_excel_to_csv.py @@ -1,7 +1,10 @@ #importing pandas as pd import pandas as pd +import os def convert_demographics_excel_to_csv(filename_xlsx,filename_csv): + if os.path.exists(filename_csv): + os.remove(filename_csv) # Read and store content # of an excel file diff --git a/demograhics.py b/demograhics.py index 9c401ad..6159099 100644 --- a/demograhics.py +++ b/demograhics.py @@ -17,22 +17,25 @@ def demographics(facility_name,sql_exported_file,heina_id): ######################################### ### create a new empty work book ######################################### - + if os.path.exists('/home/openmrs/openmrs-openshr-utils/converted.xlsx'): + os.remove('/home/openmrs/openmrs-openshr-utils/converted.xlsx') # create Workbook object - read_file = pd.read_csv (sql_exported_file,header=None) - read_file.to_csv (sql_exported_file, header=['Identifier', 'givenname', 'familyname', 'address1', 'address2', 'city', 'dateOfBirth', 'phoneNumber', 'identifier', 'gender', 'mothersMaidenName', 'familyname2', 'motherName', 'maritalstatusCode'], index = False) - - read_file = pd.read_csv (sql_exported_file) - read_file.to_excel ('/home/openmrs/openmrs-openshr-utils/converted.xlsx', index = False, header=True) - + try: + read_file = pd.read_csv (sql_exported_file,header=None) + read_file.to_csv (sql_exported_file, header=['Identifier', 'givenname', 'familyname', 'address1', 'address2', 'city', 'dateOfBirth', 'phoneNumber', 'identifier', 'gender', 'mothersMaidenName', 'familyname2', 'motherName', 'maritalstatusCode'], index = False) + + read_file = pd.read_csv (sql_exported_file) + read_file.to_excel ('/home/openmrs/openmrs-openshr-utils/converted.xlsx', index = False, header=True) + except: + print("No patients seen/consulted for this period") wb2 = Workbook() # set file path - filepath2="/home/openmrs/openmrs-openshr-utils/"+facility_name+"_HTSNew.xlsx" + filepath2 = path2="/home/openmrs/openmrs-openshr-utils/"+facility_name+"_HTSNew.xlsx" # if not os.path.exists("./data/"): # os.mkdir("data") if os.path.exists(filepath2): os.remove(filepath2) - + # save workbook wb2.save(filepath2) @@ -47,7 +50,10 @@ def demographics(facility_name,sql_exported_file,heina_id): # set file path filepath = "/home/openmrs/openmrs-openshr-utils/converted.xlsx" - # load demo.xlsx + # load demo.xlsx + if not os.path.exists(filepath): + wb3 = Workbook() + wb3.save(filepath) wb = load_workbook(filename = filepath) # select demo.xlsx diff --git a/demographics_art.py b/demographics_art.py index 10f4bd3..dc608dd 100644 --- a/demographics_art.py +++ b/demographics_art.py @@ -22,6 +22,8 @@ def demographics(facility_name,sql_exported_file,heina_id): read_file = pd.read_csv (sql_exported_file,header=None) read_file.to_csv (sql_exported_file, header=['Identifier', 'givenname', 'familyname', 'address1', 'address2', 'city', 'dateOfBirth', 'phoneNumber', 'identifier', 'gender', 'mothersMaidenName', 'familyname2', 'motherName', 'maritalstatusCode'], index = False) + if os.path.exists('/home/openmrs/openmrs-openshr-utils/converted_ART.xlsx'): + os.remove('/home/openmrs/openmrs-openshr-utils/converted_ART.xlsx') read_file = pd.read_csv (sql_exported_file) read_file.to_excel ('/home/openmrs/openmrs-openshr-utils/converted_ART.xlsx', index = False, header=True) diff --git a/find_missing_ART_clients.py b/find_missing_ART_clients.py index 2d5b93d..75f2870 100644 --- a/find_missing_ART_clients.py +++ b/find_missing_ART_clients.py @@ -1,6 +1,7 @@ from openempi_session import Openempi_session from helper import get_patients_from_csv from helper import write_data_to_csv +import os def find_missing_clients(csv_filename,facility_name): filename = csv_filename @@ -22,6 +23,10 @@ def find_missing_clients(csv_filename,facility_name): for patient in missing_patients: print(patient.givenName+" "+patient.familyName+"\n") + if os.path.exists("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_found_ART_patients.csv"): + os.remove("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_found_ART_patients.csv") + if os.path.exists("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_ART_patients.csv"): + os.remove("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_ART_patients.csv") write_data_to_csv("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_found_ART_patients.csv", found_patients) write_data_to_csv("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_ART_patients.csv", missing_patients) return "/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_ART_patients.csv" diff --git a/find_missing_clients.py b/find_missing_clients.py index 0cccfbb..65bbaec 100644 --- a/find_missing_clients.py +++ b/find_missing_clients.py @@ -1,6 +1,7 @@ from openempi_session import Openempi_session from helper import get_patients_from_csv from helper import write_data_to_csv +import os def find_missing_clients(csv_filename,facility_name): filename = csv_filename @@ -21,7 +22,10 @@ def find_missing_clients(csv_filename,facility_name): print("=================Missing Patients=================\n") for patient in missing_patients: print(patient.givenName+" "+patient.familyName+"\n") - + if os.path.exists("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_found_patients.csv"): + os.remove("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_found_patients.csv") + if os.path.exists("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_patients.csv"): + os.remove("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_patients.csv") write_data_to_csv("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_found_patients.csv", found_patients) write_data_to_csv("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_patients.csv", missing_patients) return "/home/openmrs/openmrs-openshr-utils/"+facility_name+"_missing_patients.csv" diff --git a/send_missing_clients.py b/send_missing_clients.py index fef1651..d7a7b58 100644 --- a/send_missing_clients.py +++ b/send_missing_clients.py @@ -1,6 +1,7 @@ from openempi_session import Openempi_session from helper import get_patients_from_csv from helper import write_data_to_csv +import os def send_missing_clients(missing_csv_filename,facility_name): filename = missing_csv_filename @@ -26,6 +27,10 @@ def send_missing_clients(missing_csv_filename,facility_name): for patient in failed_patients: print(patient.givenName+" "+patient.familyName+"\n") + if os.path.exists("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_sent_patients.csv"): + os.remove("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_sent_patients.csv") + if os.path.exists("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_failed_patients.csv"): + os.remove("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_failed_patients.csv") write_data_to_csv("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_sent_patients.csv", sent_patients) write_data_to_csv("/home/openmrs/openmrs-openshr-utils/"+facility_name+"_failed_patients.csv", failed_patients)