-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same issue with lines |
||
message_newline() { | ||
echo | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same issue here with whitespace editing |
||
### 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..." | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Creating Backups and Copy to Host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where exactly is |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue with name |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
fixtures = ['workup', 'core'] | ||
|
||
def test_workup_date_checker(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
There was a problem hiding this comment.
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