Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
fix: factorize main.py & fix readMe
Browse files Browse the repository at this point in the history
  • Loading branch information
BPierrick committed Jan 3, 2022
1 parent 465cb7c commit 089f40f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NB: The MinIO server will have the credentials set in the `.env` file (ie `MINIO
## Launch script to setup fake documents

```sh
python3 python/main.sh
python3 python/main.py
```

## Setup `DocumentReference` resource
Expand Down
40 changes: 13 additions & 27 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@
from minio.error import S3Error
from prescription_generator import prescription_generator


def empty_tmp_folder():
folder = "./tmp"
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e))
def create_timeline_document_table(sql_cursor):
print("Creating 'timeline_documents' table in '{}' database...".format(
POSTGRES_CREDENTIALS["database"]))
sql_cursor.execute(
"CREATE TABLE timeline_documents (patient_id INT PRIMARY KEY NOT NULL, doc_name VARCHAR(50), "
"doc_url VARCHAR(100), CONSTRAINT fk_patient FOREIGN KEY (patient_id) REFERENCES osiris_patient(patient_id))")
print("Table 'timeline_documents' successfully created !\n")


# Load .env
Expand Down Expand Up @@ -113,24 +108,15 @@ def empty_tmp_folder():

# Setup timeline_documents table
try:
print("Creating 'timeline_documents' table in '{}' database...".format(
POSTGRES_CREDENTIALS["database"]))
cur.execute(
"CREATE TABLE timeline_documents (patient_id INT PRIMARY KEY NOT NULL, doc_name VARCHAR(50), "
"doc_url VARCHAR(100), CONSTRAINT fk_patient FOREIGN KEY (patient_id) REFERENCES osiris_patient(patient_id))")
print("Table 'timeline_documents' successfully created !\n")
create_timeline_document_table(sql_cursor=cur)
except Exception as error:
print(error)
conn.commit()
print("Dropping 'timeline_documents' table...")
cur.execute("DROP TABLE timeline_documents")
print("Table 'timeline_documents' successfully dropped !")
print("Creating 'timeline_documents' table in '{}' database...".format(
POSTGRES_CREDENTIALS["database"]))
cur.execute(
"CREATE TABLE timeline_documents (patient_id INT PRIMARY KEY NOT NULL, doc_name VARCHAR(50), "
"doc_url VARCHAR(100), CONSTRAINT fk_patient FOREIGN KEY (patient_id) REFERENCES osiris_patient(patient_id))")
print("Table 'timeline_documents' successfully created !\n")
create_timeline_document_table(sql_cursor=cur)


try:
print("Reading 'osiris_patient' table, creating PDF files for each row, inserting new rows in 'timeline_documents' & uploading PDF files to MinIO...")
Expand Down Expand Up @@ -159,8 +145,8 @@ def empty_tmp_folder():

# Delete remaining files from ./tmp
print("Removing /tmp folder")
empty_tmp_folder()
# Delete tmp folder
os.rmdir("./tmp")
# # Delete tmp folder
shutil.rmtree("./tmp")


print("Done")

0 comments on commit 089f40f

Please sign in to comment.