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

Add support for Onbarding Reports #284

Open
wants to merge 5 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
20 changes: 19 additions & 1 deletion dashboard_viewer/dashboard_viewer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@ def locks_make_key(key, key_prefix, version): # noqa
"Css for the img tag displaying the app logo",
str,
),
"ALLOW_ONBOARDING_UPLOAD" :(
False,
"If Onboarding reports are allowed to be uploaded, which shows a button in the uploader page if true to allow these kind of files",
bool,
),
"CAPTION_ONBOARDING" :(
"Drug Exposure Diagnostics results for selected ingredients. Executed with minCellCount = 5, sample = 1e+06, "
"earliestStartDate = 2010-01-01. # = Number of records. Type (n,%) = Frequency and percentage of available drug types."
"Route (n,%) = Frequency and percentage of available routes. Dose Form present n (%) = Frequency and percentage with dose form present."
"Fixed amount dose form n (%) = Frequency and percentage of missing denominator unit concept id. Amount distrib. [null or missing] = Distribution of amount (median q05-q95),"
"frequency and percentage of null or missing amount. Quantity distrib. [null or missing] = Distribution of quantity (median q05-q95), frequency and percentage of null or missing quantity."
"Exposure days distrib. [null or missing] = Distribution of exposure days (median q05-q95), frequency and percentage of null days_supply or missing exposure dates."
"Neg. Days n (%) = Frequency and percentage of negative exposure days.",
"Caption Text for the table in the Onboarding Report Page",
"markdown",
),

}

CONSTANCE_CONFIG_FIELDSETS = OrderedDict(
Expand All @@ -356,9 +373,10 @@ def locks_make_key(key, key_prefix, version): # noqa
"UPLOADER_EXECUTE_EXPORT_PACKAGE",
"UPLOADER_UPLOAD",
"UPLOADER_AUTO_UPDATE",
"CAPTION_ONBOARDING"
),
),
("Uploader Settings", ("UPLOADER_ALLOW_EDIT_DRAFT_STATUS",)),
("Uploader Settings", ("UPLOADER_ALLOW_EDIT_DRAFT_STATUS", "ALLOW_ONBOARDING_UPLOAD")),
(
"Superset",
("SUPERSET_HOST", "DATABASE_DASHBOARD_IDENTIFIER", "DATABASE_FILTER_ID"),
Expand Down
8 changes: 7 additions & 1 deletion dashboard_viewer/uploader/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ class Meta(SourceForm.Meta):


class AchillesResultsForm(forms.Form):
results_file = forms.FileField()
if constance.config.ALLOW_ONBOARDING_UPLOAD:
results_file = forms.FileField(required=False, label='Catalogue Export File')
else:
results_file = forms.FileField()

class OnboardingReportForm(forms.Form):
onboarding_results_file = forms.FileField(required=False, label='Onboarding Report file (Optional)')
26 changes: 26 additions & 0 deletions dashboard_viewer/uploader/migrations/0014_onboardingreport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.13 on 2024-03-27 12:05

from django.db import migrations, models
import django.db.models.deletion
import uploader.models


class Migration(migrations.Migration):

dependencies = [
('uploader', '0013_auto_20210721_1715'),
]

operations = [
migrations.CreateModel(
name='OnBoardingReport',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uploaded_file', models.FileField(null=True, upload_to=uploader.models.onboarding_folder)),
('data_source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uploader.datasource')),
],
options={
'db_table': 'onboarding_report',
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.13 on 2024-03-28 12:35

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('uploader', '0014_onboardingreport'),
]

operations = [
migrations.AddField(
model_name='onboardingreport',
name='upload_date',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]
22 changes: 22 additions & 0 deletions dashboard_viewer/uploader/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ def success_data_source_directory(instance, filename):

return datetime.datetime.now().strftime(file_path)

def onboarding_folder(instance, filename):
file_path = os.path.join(
settings.ACHILLES_RESULTS_STORAGE_PATH,
instance.data_source.hash,
"onboarding",
"%Y%m%d%H%M%S%f" + "".join(pathlib.Path(filename).suffixes),
)
return datetime.datetime.now().strftime(file_path)


class UploadHistory(models.Model):
"""
Expand Down Expand Up @@ -266,3 +275,16 @@ class Meta:
p25_value = models.FloatField(null=True)
p75_value = models.FloatField(null=True)
p90_value = models.FloatField(null=True)

class OnboardingReport(models.Model):
class Meta:
db_table = "onboarding_report"

data_source = models.ForeignKey(DataSource, on_delete=models.CASCADE)
upload_date = models.DateTimeField(auto_now_add=True)
uploaded_file = models.FileField(
null=True, upload_to=onboarding_folder
)

def get_status(self):
return "Done"
14 changes: 8 additions & 6 deletions dashboard_viewer/uploader/static/js/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ document.addEventListener("DOMContentLoaded", () => {
const tbody = tbodys[0];

for (const tr of tbody.children) {
const status_td = tr.children[5];

const numberOfColumns = tr.children.length;
const status_td = tr.children[numberOfColumns-1];


if (status_td.dataset.failed === "yes") {
add_failure_message_popup(status_td, status_td.dataset.failureMsg);
}
Expand All @@ -37,10 +39,10 @@ document.addEventListener("DOMContentLoaded", () => {
.then(r => r.json())
.then(r => {
if (r.status === "Done") {
tr.children[1].innerText = r.data.r_package_version;
tr.children[2].innerText = r.data.generation_date;
tr.children[3].innerText = r.data.cdm_version;
tr.children[4].innerText = r.data.vocabulary_version;
tr.children[numberOfColumns - 5].innerText = r.data.r_package_version;
tr.children[numberOfColumns - 4].innerText = r.data.generation_date;
tr.children[numberOfColumns - 3].innerText = r.data.cdm_version;
tr.children[numberOfColumns - 2].innerText = r.data.vocabulary_version;

update_upload_status(status_td, "Done", "fas fa-check", "status-done");

Expand Down
80 changes: 80 additions & 0 deletions dashboard_viewer/uploader/templates/onboarding_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% extends 'base.html' %}
{% load static %}
{% load bootstrap4 %}
{% load markdownify %}

{% block head_tail %}
{{ form.media.css }}
<link rel="stylesheet" href='{% static "pages.css" %}' >
<link rel="stylesheet" href='{% static "header.css" %}' >
<link rel="stylesheet" href='{% static "css/uploader.css" %}' >
{% endblock %}


{% block content %}
<div>
{% include "header.html" %}

{# Achilles resutls file form #}
<div class="content-container" >
<div class="row">
<h3 class="col">Data Source: {{ obj_data_source.name }}</h3>
</div>
<div class="row">
<div class="col">
<p><b>Database type:</b> {{ obj_data_source.database_type }}</p>
</div>
<div class="col">
<p><b>Country:</b> {{ obj_data_source.country }}</p>
</div>
<div class="col-auto">
<p><b>Release date:</b> {{ obj_data_source.release_date }}</p>
</div>
</div>

<hr/>
<h3 style="margin-top: 15px;">Onboarding Report</h3>
<div style="margin-top: 15px;text-align: center;">
{% if body|length > 0 %}
<table class="table center table-stripped" style="font-size: 14px;margin-top: 20px;width: 95%;">
<caption style="text-align:left"> {{ constance_config.CAPTION_ONBOARDING|markdownify }}</caption>
<thead style="background-color: #023E8a;color: white">
<tr>
{% for header in headers %}
<th> {{ header }}</th>
{% endfor %}
</tr>
</thead>
<tbody style="background-color: #f5fbff;">
{% for list in body %}
<tr>
{% for el in list %}
<td>{{ el }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Onboarding report is not available.</p>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% block body_before_bootstrap %}
<style>
table
{
margin-left: auto;
margin-right: auto;
border-collapse : collapse;
}
caption { caption-side:top; }
table td, table th
{
max-width: 100px;
word-wrap: break-word;
}
</style>
{% endblock %}
10 changes: 8 additions & 2 deletions dashboard_viewer/uploader/templates/upload_achilles_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3>Upload new database characteristics</h3>
For more information see the CatalogueExport R-package
<a href="https://github.com/EHDEN/CatalogueExport">
<i class="fas fa-link"></i>
</a>
</a> {%if constance_config.ALLOW_ONBOARDING_UPLOAD %}<br> You can also upload an Onboarding Report {% endif %}
</span>

{% endblock %}
Expand All @@ -43,6 +43,9 @@ <h3>Upload history</h3>
<table class="table">
<thead>
<tr>
{% if constance_config.ALLOW_ONBOARDING_UPLOAD %}
<th>Type</th>
{% endif %}
<th>Upload Date</th>
<th>R Package Version</th>
<th>Generation Date</th>
Expand All @@ -52,8 +55,11 @@ <h3>Upload history</h3>
</tr>
</thead>
<tbody>
{% for up_hi, status in upload_history %}
{% for up_hi, status, type in upload_history %}
<tr>
{% if constance_config.ALLOW_ONBOARDING_UPLOAD %}
<td>{{ type }}</td>
{% endif %}
<td>{{ up_hi.upload_date }}</td>
<td>{% if up_hi.r_package_version %}{{ up_hi.r_package_version }}{% else %}--{% endif %}</td>
<td>{% if up_hi.generation_date %}{{ up_hi.generation_date }}{% else %}--{% endif %}</td>
Expand Down
13 changes: 12 additions & 1 deletion dashboard_viewer/uploader/templates/uploader_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@
{% block title %}{% endblock %}

<form id="uploadForm" method="POST" enctype="multipart/form-data">
{% bootstrap_form form %}
{% if constance_config.ALLOW_ONBOARDING_UPLOAD and onboarding_form %}
<div class="row">
<div class="col-6 col-sm-3">
{% bootstrap_form form %}
</div>
<div class="col-6 col-sm-3">
{% bootstrap_form onboarding_form %}
</div>
</div>
{% else %}
{% bootstrap_form form %}
{% endif %}

{% buttons %}
<button type="submit" class="btn btn-primary btn-sm-lg" >
Expand Down
5 changes: 5 additions & 0 deletions dashboard_viewer/uploader/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
views.data_source_dashboard,
name="data_source_dashboard",
),
path(
"<str:data_source>/OnboardingReport/",
views.show_onboarding_csv,
name="show_onboarding_csv"
)
]
Loading