Skip to content

Commit

Permalink
TN-3184, report any in-process QNRs attempting to change authored dat…
Browse files Browse the repository at this point in the history
…es (#4336)

When a questionnaire response is UPDATED (via PUT from the assessment
engine), make a note of the situation in the audit log, and log a
warning as per TN-3184.

Example audit generated when testing:
```
 410347 |     128 |       4032 | assessment     | 2023-08-28 23:15:56.849448 | 2
3.7.24.3.dev4+g5b2dcee5.d20161205 | updated QuestionnaireResponse 4175 for user
4032 completed 2023-01-08T20:00:00Z UNEXPECTED authored change; was previously 2
023-01-04T20:00:00Z
```
  • Loading branch information
pbugni authored Sep 6, 2023
1 parent e4b6552 commit 1c08c21
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion portal/views/assessment_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,13 @@ def assessment_update(patient_id):

response.update({'message': 'previous questionnaire response found'})
existing_qnr = existing_qnr.first()

# TN-3184, report any in-process QNRs attempting to change authored dates
date_change_snippet = ""
if FHIR_datetime.parse(existing_qnr.document["authored"]) != FHIR_datetime.parse(updated_qnr["authored"]):
date_change_snippet = f" UNEXPECTED authored change; was previously {existing_qnr.document['authored']}"
current_app.logger.warning(date_change_snippet)

existing_qnr.status = updated_qnr["status"]
existing_qnr.document = updated_qnr
db.session.add(existing_qnr)
Expand All @@ -1001,7 +1008,7 @@ def assessment_update(patient_id):
kwargs={'questionnaire_response_id': existing_qnr.id}
)
auditable_event(
"updated {}".format(existing_qnr),
f"updated {existing_qnr}{date_change_snippet}",
user_id=current_user().id,
subject_id=patient.id,
context='assessment',
Expand Down

0 comments on commit 1c08c21

Please sign in to comment.