diff --git a/backups/backup_2022_03_31T03_08_29.sql.gz b/backups/backup_2022_03_31T03_08_29.sql.gz new file mode 100644 index 00000000..17a945c5 Binary files /dev/null and b/backups/backup_2022_03_31T03_08_29.sql.gz differ diff --git a/compose/production/postgres/maintenance/_sourced/constants.sh b/compose/production/postgres/maintenance/_sourced/constants.sh index 6ca4f0ca..e1b903f2 100644 --- a/compose/production/postgres/maintenance/_sourced/constants.sh +++ b/compose/production/postgres/maintenance/_sourced/constants.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash - BACKUP_DIR_PATH='/backups' BACKUP_FILE_PREFIX='backup' diff --git a/compose/production/postgres/maintenance/_sourced/countdown.sh b/compose/production/postgres/maintenance/_sourced/countdown.sh index e6cbfb6f..3e228204 100644 --- a/compose/production/postgres/maintenance/_sourced/countdown.sh +++ b/compose/production/postgres/maintenance/_sourced/countdown.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash - countdown() { declare desc="A simple countdown. Source: https://superuser.com/a/611582" local seconds="${1}" diff --git a/compose/production/postgres/maintenance/_sourced/messages.sh b/compose/production/postgres/maintenance/_sourced/messages.sh index f6be756e..acbe26e3 100644 --- a/compose/production/postgres/maintenance/_sourced/messages.sh +++ b/compose/production/postgres/maintenance/_sourced/messages.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash - message_newline() { echo } diff --git a/compose/production/postgres/maintenance/backup b/compose/production/postgres/maintenance/backup index ee0c9d63..d1ecd2c2 100644 --- a/compose/production/postgres/maintenance/backup +++ b/compose/production/postgres/maintenance/backup @@ -1,6 +1,5 @@ #!/usr/bin/env bash - ### Create a database backup. ### ### Usage: @@ -16,7 +15,6 @@ working_dir="$(dirname ${0})" source "${working_dir}/_sourced/constants.sh" source "${working_dir}/_sourced/messages.sh" - message_welcome "Backing up the '${POSTGRES_DB}' database..." diff --git a/config/urls.py b/config/urls.py index 0282dbad..151811f2 100644 --- a/config/urls.py +++ b/config/urls.py @@ -28,7 +28,7 @@ path('labs/', include('osler.labs.urls')), path('inventory/', include('osler.inventory.urls')), path('surveys/', include('osler.surveys.urls')), - # path('datadashboard/', include('osler.datadashboard.urls')), + #path('datadashboard/', include('osler.datadashboard.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # API URLS diff --git a/docs/conf.py b/docs/conf.py index 144bfc00..1d1c2429 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,13 +3,10 @@ # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html - # -- Path setup -------------------------------------------------------------- - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. - import os import datetime import sys diff --git a/docs/technical-reference/makingBackups.rst b/docs/technical-reference/makingBackups.rst new file mode 100644 index 00000000..ca2a570c --- /dev/null +++ b/docs/technical-reference/makingBackups.rst @@ -0,0 +1,26 @@ +Creating Backups and Copy to Host +====================================================================== + +Create Backups +---------------------------------------------------------------------- + +To create a backup of the postgres container, use the command: + :: + + docker-compose -f production.yml (exec |run --rm) postgres backup + +If you are on windows and the above command doesn't work, delete the headings in the script files you are calling, rebuild and run the server, and then use the command: + :: + + docker exec -it llemr_postgres_1 /bin/bash usr/local/bin/backup + +Note: If you want to view all of the backups you have created in the postgres container, replace backup with backups in the above commands + + +Copy to Host +---------------------------------------------------------------------- + +This command will copy the backups you have created to your local machine: + :: + + docker cp llemr_postgres_1:./backups . diff --git a/osler/workup/scripts/workup_date_checker.py b/osler/workup/scripts/workup_date_checker.py new file mode 100644 index 00000000..06f383aa --- /dev/null +++ b/osler/workup/scripts/workup_date_checker.py @@ -0,0 +1,45 @@ +""" +Script that identifies all workups whose encounter date differs from the written_datetime by more than 7 days +and for each of these workups print the patient name, author name, the written_datetime, and the encounter date + +Instructions for running this script are located in (PUT THE PLACE THAT I PUT THE DOC FILE IN) [note: I need to make docs for this] +""" + +from osler.workup.models import Workup +from datetime import datetime + +NAME = 'django.core.management.commands.shell' + +def days_between(d1, d2): + '''computes number of days between two date objects''' + delta = d2 - d1 + return abs(delta.days) + + +def get_returned_workups(n): + '''check if written_date differs from encounter_date by more than n days for each workup''' + all_workups = Workup.objects.all() + returned_workups = [] + for workup in all_workups: + if days_between(workup.encounter.clinic_day, datetime.date(workup.written_datetime)) >= n: + returned_workups.append(workup) + return returned_workups + + +def print_returned_workups(returned_workups): + '''for each workup in returned_workups, print the patient name, author name, written_datetime, and the encounter date''' + print("All workups whose encounter date differs from the written_datetime by more than 7 days: ") + for i, workup in enumerate(returned_workups): + st1 = f"Workup {i} | Patient name: {workup.patient.name()}, Author name: {workup.signer}, Date " + st2 = f"written: {datetime.date(workup.written_datetime)}, Encounter date: {workup.encounter.clinic_day}" + print(st1 + st2) + + +def out_of_date_workup_finder(): + returned_workups = get_returned_workups(7) + print_returned_workups(returned_workups) + return returned_workups + + +if __name__ == NAME: + out_of_date_workup_finder() \ No newline at end of file diff --git a/osler/workup/tests/test_scripts.py b/osler/workup/tests/test_scripts.py new file mode 100644 index 00000000..99d239c5 --- /dev/null +++ b/osler/workup/tests/test_scripts.py @@ -0,0 +1,31 @@ +from django.test import TestCase +from osler.workup.models import Workup +from osler.workup.scripts import workup_date_checker +from .factories import WorkupFactory +import datetime + +class testScripts(TestCase): + + fixtures = ['workup', 'core'] + + def test_workup_date_checker(self): + d1 = datetime.datetime(2019, 4, 13) + d2 = datetime.datetime.now() - datetime.timedelta(days=2) + d3 = datetime.datetime(2018, 4, 4) + + workup_one = WorkupFactory() + workup_two = WorkupFactory() + workup_three = WorkupFactory() + + workup_one.written_datetime = d1 + workup_two.written_datetime = d2 + workup_three.written_datetime = d3 + + workup_one.save() + workup_two.save() + workup_three.save() + + expected_returned_workups = [workup_one, workup_three] + assert workup_date_checker.out_of_date_workup_finder() == expected_returned_workups + +