Skip to content

Commit

Permalink
Merge branch 'release/v22.8.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-c committed Aug 18, 2022
2 parents 32c9722 + 4e656a1 commit 244b449
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 11 deletions.
2 changes: 2 additions & 0 deletions portal/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,13 @@ def token_janitor():
body=body)
try:
em.send_message()
db.session.add(em)
except SMTPRecipientsRefused as exc:
msg = ("Error sending site summary email to {}: "
"{}".format(sponsor_email, exc))
current_app.logger.error(msg)
for email in exc[0]:
error_emails.add(email)

db.session.commit()
return list(error_emails)
3 changes: 3 additions & 0 deletions portal/models/qb_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def _indef_init(self):
for q in qbs:
if self._current_indef is not None:
raise RuntimeError("unexpected second indef qb")
if q.relative_start > self.as_of_date:
# Don't include if the consent date hasn't arrived
continue
self._current_indef = q

def indef_status(self):
Expand Down
3 changes: 3 additions & 0 deletions portal/models/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ..audit import auditable_event
from ..cache import cache
from ..database import db
from ..date_tools import FHIR_datetime
from ..trigger_states.models import TriggerStatesReporting
from .app_text import MailResource, SiteSummaryEmail_ATMA, app_text
Expand Down Expand Up @@ -403,6 +404,7 @@ def generate_and_send_summaries(org_id):
body=summary_email.body)
try:
em.send_message()
db.session.add(em)
except SMTPRecipientsRefused as exc:
msg = ("Error sending site summary email to {}: "
"{}".format(staff_user.email, exc))
Expand All @@ -418,4 +420,5 @@ def generate_and_send_summaries(org_id):
for email in exc[0]:
error_emails.add(email)

db.session.commit()
return error_emails or None
8 changes: 4 additions & 4 deletions portal/static/js/src/modules/TnthAjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default { /*global $ */
},
"sendRequest": function(url, method, userId, params, callback) {
if (!url) { return false; }
var REQUEST_TIMEOUT_INTERVAL = 5000;
var defaultParams = {type: method ? method : "GET", url: url, attempts: 0, max_attempts: MAX_ATTEMPTS, contentType: "application/json; charset=utf-8", dataType: "json", sync: false, timeout: 5000, data: null, useWorker: false, async: true};
var REQUEST_TIMEOUT_INTERVAL = 5000; // default timed out at 5 seconds
var defaultParams = {type: method ? method : "GET", url: url, attempts: 0, max_attempts: MAX_ATTEMPTS, contentType: "application/json; charset=utf-8", dataType: "json", sync: false, timeout: REQUEST_TIMEOUT_INTERVAL, data: null, useWorker: false, async: true};
params = params || defaultParams;
params = $.extend({}, defaultParams, params);
params.timeout = params.timeout || REQUEST_TIMEOUT_INTERVAL;
Expand Down Expand Up @@ -75,8 +75,8 @@ export default { /*global $ */
}).fail(function(xhr) {
if (params.attempts < params.max_attempts) {
(function(self, url, method, userId, params, callback) {
setTimeout(function() {
self.sendRequest(url, method, userId, params, callback);
setTimeout(function () {
self.sendRequest(url, method, userId, params, callback);
}, REQUEST_TIMEOUT_INTERVAL); //retry after 5 seconds
})(self, url, method, userId, params, callback);
} else {
Expand Down
3 changes: 2 additions & 1 deletion portal/static/js/src/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2994,7 +2994,8 @@ export default (function() {
var self = this, errorMessage = "";
$("#profileAuditLogTable").html(Utility.getLoaderHTML());
$("#profileAuditLogTable .loading-message-indicator").show();
this.modules.tnthAjax.auditLog(this.subjectId, {useWorker:true}, function(data) {
// set request times out at 5 minutes
this.modules.tnthAjax.auditLog(this.subjectId, {useWorker:true, timeout: 5 * 60 * 1000}, function(data) {
if (data.error) {
errorMessage = i18next.t("Error retrieving data from server");
}
Expand Down
4 changes: 2 additions & 2 deletions portal/trigger_states/empro_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
from ..models.questionnaire_bank import QuestionnaireBank
from ..models.questionnaire_response import QuestionnaireResponse
from ..models.observation import Observation
from ..models.research_study import EMPRO_RS_ID
from ..models.user import User
from ..timeout_lock import TimeoutLock

EMPRO_STUDY_ID = 1
EMPRO_LOCK_KEY = "empro-trigger-state-lock-{user_id}"


Expand Down Expand Up @@ -317,7 +317,7 @@ def process_pending_actions(ts):
# Withdrawn users should never receive reminders, nor staff
# about them.
qb_status = QB_Status(
user=patient, research_study_id=EMPRO_STUDY_ID, as_of_date=now)
user=patient, research_study_id=EMPRO_RS_ID, as_of_date=now)
if qb_status.withdrawn_by(now):
triggers = copy.deepcopy(ts.triggers)
triggers['action_state'] = 'withdrawn'
Expand Down
5 changes: 2 additions & 3 deletions portal/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from ..models.qb_timeline import QB_StatusCacheKey, invalidate_users_QBT
from ..models.questionnaire_response import QuestionnaireResponse
from ..models.relationship import Relationship
from ..models.research_study import EMPRO_RS_ID
from ..models.role import ROLE, Role
from ..models.table_preference import TablePreference
from ..models.url_token import url_token
Expand Down Expand Up @@ -962,8 +963,6 @@ def delete_user_consents(user_id):
- ServiceToken: []
"""
from portal.trigger_states.empro_states import EMPRO_STUDY_ID

current_app.logger.debug('delete user consent called w/: {}'.format(
request.json))
user = get_user(user_id, 'edit')
Expand All @@ -983,7 +982,7 @@ def delete_user_consents(user_id):
abort(404, "matching user consent not found")

audit_comment = 'Deleted consent agreement'
if research_study_id == EMPRO_STUDY_ID:
if research_study_id == EMPRO_RS_ID:
audit_comment = 'Deleted EMPRO consent agreement'
remove_uc.deleted = Audit(
user_id=current_user().id, subject_id=user_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_assessment_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def test_qnr_id_missing(self):

def test_enrolled_in_metastatic(self):
"""metastatic should include baseline and indefinite"""
self.bless_with_basics(local_metastatic='metastatic')
self.bless_with_basics(local_metastatic='metastatic', setdate=now)
user = db.session.merge(self.test_user)

a_s = QB_Status(
Expand Down
28 changes: 28 additions & 0 deletions tests/test_qb_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,34 @@ def test_indef_change_before_start_rp_w_result(self):
with pytest.raises(StopIteration):
next(gen)

def test_indef_assignment_post_consent(self):
org = self.setup_org_qbs(rp_name='v3', include_indef=True)
org_id = org.id
back7, nowish = associative_backdate(
now=now, backdate=relativedelta(months=7))
self.consent_with_org(org_id=org_id, setdate=back7)
user = db.session.merge(self.test_user)

a_s = QB_Status(
user=user,
research_study_id=0,
as_of_date=nowish)
assert a_s.enrolled_in_classification('indefinite')

def test_indef_assignment_pre_consent(self):
org = self.setup_org_qbs(rp_name='v3', include_indef=True)
org_id = org.id
tomorrow, nowish = associative_backdate(
now=now, backdate=relativedelta(days=-1))
self.consent_with_org(org_id=org_id, setdate=tomorrow)
user = db.session.merge(self.test_user)

a_s = QB_Status(
user=user,
research_study_id=0,
as_of_date=nowish)
assert a_s.enrolled_in_classification('indefinite') is None


class Test_QB_StatusCacheKey(TestCase):

Expand Down

0 comments on commit 244b449

Please sign in to comment.