Skip to content

Commit

Permalink
Merge pull request #870 from openhealthcare/v0.29
Browse files Browse the repository at this point in the history
V0.29
  • Loading branch information
davidmiller authored Mar 27, 2020
2 parents 6d253d5 + 69b18fe commit 8b7e353
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 10 deletions.
11 changes: 10 additions & 1 deletion deployment_tests/fabric_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,11 @@ def test_services_symlink_upstart_if_exists(
)

@mock.patch('fabfile.local')
@mock.patch('fabfile.generate_secret_key')
def test_sevices_create_local_settings(
self, local, print_function
self, generate_secret_key, local, print_function
):
generate_secret_key.return_value = "blah"
some_dir = tempfile.mkdtemp()
project_dir = "{}/elcid".format(some_dir)
os.mkdir(project_dir)
Expand All @@ -514,6 +516,7 @@ def test_sevices_create_local_settings(

self.assertIn("Some = 'settings'", output_file)
self.assertIn("'NAME': 'elcidrfh_some_branch'", output_file)
self.assertIn('SECRET_KEY = "blah"', output_file)

local.assert_called_once_with(
"rm -f {}".format(local_settings_file)
Expand Down Expand Up @@ -1405,6 +1408,12 @@ def test_error_not_raised(
clean_old_backups.assert_called_once_with()


class GenerateSecretKeyTestCase(FabfileTestCase):
def test_generate_secret_key(self):
result = fabfile.generate_secret_key()
self.assertEqual(len(result), 50)


@mock.patch("fabfile.is_load_running")
@mock.patch("fabfile.local")
@mock.patch("fabfile.time")
Expand Down
40 changes: 39 additions & 1 deletion elcid/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,42 @@ class InfectionServiceTestSummaryApi(LoginRequiredViewset):

NUM_RESULTS = 5

def get_ticker_observations(self, patient):
"""
Some results are displayed as a ticker in chronological
order.
"""
ticker = []
tests = lab_test_models.LabTest.objects.filter(
test_name='2019 NOVEL CORONAVIRUS',
patient=patient
).order_by('-datetime_ordered')
for test in tests:
if len(ticker) < 3:
observations = {
t.observation_name: t for t in test.observation_set.all()
}
value = observations['2019 nCoV'].observation_value
if value == 'Pending':
continue

specimen = observations.get('2019 nCoV Specimen Type', None)
timestamp = test.datetime_ordered.strftime('%d/%m/%Y %H:%M')
result_string = "{}".format(value)

if specimen:
result_string += " ({})".format(specimen.observation_value)

ticker.append(
{
'timestamp': timestamp,
'name': '2019 nCoV',
'value': result_string
}
)

return ticker

def get_recent_dates_to_observations(self, qs):
"""
We are looking for the last 5 dates
Expand Down Expand Up @@ -339,13 +375,15 @@ def serialise_lab_tests(self, patient):
# the patient does not have a lot of results
while len(recent_dates) < self.NUM_RESULTS:
recent_dates.append(None)

obs_values = []

for obs_set in obs:
obs_values.append(self.serialize_observations(obs_set))
return dict(
obs_values=obs_values,
recent_dates=recent_dates
recent_dates=recent_dates,
ticker=self.get_ticker_observations(patient)
)

@patient_from_pk
Expand Down
18 changes: 18 additions & 0 deletions elcid/migrations/0035_auto_20200326_1517.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.9 on 2020-03-26 15:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('elcid', '0034_auto_20200323_1813'),
]

operations = [
migrations.AlterField(
model_name='icuadmission',
name='outcome',
field=models.CharField(blank=True, choices=[('Survived', 'Survived'), ('Covid-19 Atributable Death', 'Covid-19 Atributable Death'), ('Covid-19 Non-attributable Death', 'Covid-19 Non-attributable Death')], max_length=200, null=True),
),
]
2 changes: 1 addition & 1 deletion elcid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def record_positive_blood_culture(sender, instance, **kwargs):
class ICUAdmission(EpisodeSubrecord):
_icon = 'fa fa-heartbeat'

OUTCOMES = enum('Survived', 'Atributable Death', 'Non-attributable Death')
OUTCOMES = enum('Survived', 'Covid-19 Atributable Death', 'Covid-19 Non-attributable Death')

admission_date = models.DateField(blank=True, null=True)
discharge_date = models.DateField(blank=True, null=True)
Expand Down
23 changes: 16 additions & 7 deletions elcid/templates/partials/lab_test_sparklines.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ <h2 class="text-center no-results">Unable to get lab tests for this patient</h2>
<h2 class="text-center no-results">Failed To load lab tests for this patient</h2>
</div>
<div ng-show="patientLoadStatus.isLoaded()">
<div ng-hide="data.obs_values.length">
<div ng-hide="data.obs_values.length || data.ticker.length">
<h2 class="text-center no-results">No results found</h2>
</div>

<div class="content-offset-below-20" ng-show="data.ticker.length">
<div class="row" ng-repeat="test in data.ticker">
<div class="col-md-4">[[ test.timestamp ]]</div>
<div class="col-md-4">[[ test.name ]]</div>
<div class="col-md-4">[[ test.value ]]</div>
</div>
</div>

<table ng-show="data.obs_values.length" class="col-md-12 table">
<thead>
<tr>
Expand All @@ -23,9 +32,9 @@ <h2 class="text-center no-results">No results found</h2>
[[ date | displayDate ]]
</th>
{% comment %}
<th class="text-center">
3 week trend
</th>
<th class="text-center">
3 week trend
</th>
{% endcomment %}
</tr>
</thead>
Expand All @@ -37,9 +46,9 @@ <h2 class="text-center no-results">No results found</h2>
[[ item.latest_results[date] ]]
</td>
{% comment %}
<td class="text-center">
<div spark-line="item.graph_values"></div>
</td>
<td class="text-center">
<div spark-line="item.graph_values"></div>
</td>
{% endcomment %}
</tr>
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions elcid/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ def test_vanilla_check(self):

result = self.client.get(self.url)
expected = {
'ticker': [],
'obs_values': [
{
'latest_results': {'04/06/2019': 1.8, '05/06/2019': 1.8},
Expand Down Expand Up @@ -1020,6 +1021,7 @@ def test_multiple_results_on_the_same_day(self):
})
result = self.client.get(self.url)
expected = {
'ticker': [],
'obs_values': [
{
'latest_results': {'04/06/2019': 1.3},
Expand Down Expand Up @@ -1061,6 +1063,7 @@ def test_results_date_crunching(self):
dt_4: "1.4", dt_5: "1.5", dt_6: "1.6", dt_7: "1.7", dt_8: "1.8"
})
expected = {
'ticker': [],
'obs_values':
[
{
Expand Down Expand Up @@ -1109,6 +1112,7 @@ def test_ignores_strings(self):
})
result = self.client.get(self.url)
expected = {
'ticker': [],
'obs_values': [],
'recent_dates': [None, None, None, None, None]
}
Expand All @@ -1124,6 +1128,7 @@ def test_ignore_strings_same_date(self):
def test_handles_no_tests(self):
result = self.client.get(self.url)
expected = {
'ticker': [],
'obs_values': [],
'recent_dates': [None, None, None, None, None]
}
Expand Down
2 changes: 2 additions & 0 deletions etc/conf_templates/local_settings.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ DATABASES = {
}
}

SECRET_KEY = "{{ secret_key }}"

DEBUG = False

{% for k, v in additional_settings.items() %}
Expand Down
7 changes: 7 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import json
import copy
import time
import random
from jinja2 import Environment, FileSystemLoader

from fabric.api import local, env
Expand Down Expand Up @@ -326,12 +327,18 @@ def services_symlink_upstart(new_env):
symlink_name
))

def generate_secret_key():
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
return ''.join([
random.SystemRandom().choice(chars) for i in range(50)
])

def services_create_local_settings(new_env, additional_settings):
print("Creating local settings")
new_settings = copy.copy(additional_settings)
new_settings["db_name"] = new_env.database_name
new_settings["db_user"] = DB_USER
new_settings["secret_key"] = generate_secret_key()
template = jinja_env.get_template(
'etc/conf_templates/local_settings.py.jinja2'
)
Expand Down

0 comments on commit 8b7e353

Please sign in to comment.