Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added backup documentation and workup script #76

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added backups/backup_2022_03_31T03_08_29.sql.gz
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash


BACKUP_DIR_PATH='/backups'
BACKUP_FILE_PREFIX='backup'
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash


countdown() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't edit unnecessary files to adjust whitespace

declare desc="A simple countdown. Source: https://superuser.com/a/611582"
local seconds="${1}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue with lines

message_newline() {
echo
}
Expand Down
2 changes: 0 additions & 2 deletions compose/production/postgres/maintenance/backup
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue here with whitespace editing

### Create a database backup.
###
### Usage:
Expand All @@ -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..."


Expand Down
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

#path('datadashboard/', include('osler.datadashboard.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# API URLS
Expand Down
3 changes: 0 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace editing

# -- 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
Expand Down
26 changes: 26 additions & 0 deletions docs/technical-reference/makingBackups.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Creating Backups and Copy to Host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide documentation on how to load backups as well?

======================================================================

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
Comment on lines +12 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to confirm that deleting the headings is necessary? If it is necessary, would it be valid to delete the headings across the board? Having two different versions of the files for different operating systems is not something that I want to have happen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where exactly is llemr_postgres_1 coming from? This name seems hardcoded, and I wouldn't be surprised if it was different from one person's computer to another. You should detail how to get that name


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 link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to paste the command again



Copy to Host
----------------------------------------------------------------------

This command will copy the backups you have created to your local machine:
::

docker cp llemr_postgres_1:./backups .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue with name

45 changes: 45 additions & 0 deletions osler/workup/scripts/workup_date_checker.py
Original file line number Diff line number Diff line change
@@ -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]
"""
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do this before I can approve the pull request


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()
31 changes: 31 additions & 0 deletions osler/workup/tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class name sounds generic, also the first letter should be capitalized. Something like TestUtilityScripts could work


fixtures = ['workup', 'core']

def test_workup_date_checker(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this test works when you don't specify the encounter date for the test workups.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add an additional tests to check individual functions, such as whether the differ by n days function works for exactly n days

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
Comment on lines +16 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to specify the written datetime when creating the workup. If this is not already allowed, you should edit WorkupFactory to allow this


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