Skip to content

Commit

Permalink
TN-2417 provide ugly workaround to failed query until we can figure o…
Browse files Browse the repository at this point in the history
…ut the source of the problem. (#3579)
  • Loading branch information
pbugni authored and ivan-c committed Dec 10, 2019
1 parent 57c1fb5 commit 08a7642
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion portal/models/questionnaire_response.py
Expand Up @@ -340,15 +340,41 @@ def qnrs(self):
).filter(
QuestionnaireResponse.qb_iteration == self.qb_iteration)
self._qnrs = []
requery = False
for qnr in query:
if qnr.instrument_id is None:
current_app.logger.warning(
"QNR {} query returned no instrument".format(qnr.id))
instrument = None
requery = True
else:
instrument = qnr.instrument_id.split('/')[-1]
self._qnrs.append(QNR(
qnr_id=qnr.id,
qb_id=qnr.questionnaire_bank_id,
iteration=qnr.qb_iteration,
status=qnr.status,
instrument=qnr.instrument_id.split('/')[-1],
instrument=instrument,
authored=qnr.authored,
encounter_id=qnr.encounter_id))

if requery:
# Ugly workaround till we figure out why this is happening
# see TN-2417
for i, qnr in enumerate(self._qnrs):
if qnr.instrument is None:
doc = QuestionnaireResponse.query.filter(
QuestionnaireResponse.id == qnr.qnr_id).with_entities(
QuestionnaireResponse.document).first()
if doc is None:
current_app.logger.warning(
"doc still None on second try for "
"qnr {}".format(qnr.qnr_id))
else:
self._qnrs[i] = qnr._replace(
instrument=
doc[0]['questionnaire']['reference'].split(
'/')[-1])
return self._qnrs

def assign_qb_relationships(self, qb_generator):
Expand Down

0 comments on commit 08a7642

Please sign in to comment.