Skip to content

Commit

Permalink
fix blank text in study evaluations (#648)
Browse files Browse the repository at this point in the history
* fix blank text

* fix widget

* (unrelated) rename study extraction to study details

Co-authored-by: Daniel Rabstejnek <[email protected]>
  • Loading branch information
shapiromatron and rabstejnek authored Jul 12, 2022
1 parent 0906eb7 commit d094598
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 34 deletions.
2 changes: 1 addition & 1 deletion frontend/lit/components/Reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Reference extends Component {
) : null}
{data.has_study ? (
<p className="my-1">
<strong>HAWC study extraction:&nbsp;</strong>
<strong>HAWC study details:&nbsp;</strong>
<a href={reference.get_study_url()}>{data.study_short_citation}</a>
</p>
) : null}
Expand Down
40 changes: 25 additions & 15 deletions frontend/riskofbias/robStudyForm/Completeness.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ import PropTypes from "prop-types";

class Completeness extends Component {
render() {
let display =
this.props.number > 0 ? (
<div className="alert alert-danger">
<p>{this.props.number} note(s) still need input.</p>
<p>
Notes should only be left blank if &quot;Not applicable&quot; judgment is
selected.
</p>
</div>
) : (
<div className="alert alert-success">
<p>All items complete! Ready to submit.</p>
</div>
);
return display;
const {number} = this.props,
className = number > 0 ? "alert alert-danger" : "alert alert-success",
message =
number === 0
? "All items complete! Ready to submit."
: number === 1
? "1 item still needs input:"
: `${number} items still need input:`;
return (
<div className={className}>
<p>{message}</p>
{number > 0 ? (
<ul>
<li>
Notes are required if the &quot;Not reported&quot; judgment is selected.
</li>
<li>
It is recommended, but not required, to add notes for all other
judgments (except for &quot;Not applicable&quot;, which is
self-explanatory)
</li>
</ul>
) : null}
</div>
);
}
}

Expand Down
14 changes: 9 additions & 5 deletions frontend/riskofbias/robStudyForm/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ class RobFormStore extends StudyRobStore {
return _.find(this.activeRobs, {id: this.config.riskofbias.id});
}
@computed get numIncompleteScores() {
return this.editableScores.filter(score => {
return (
_.includes(NR_KEYS, score.score) && score.notes.replace(/<\/?[^>]+(>|$)/g, "") == ""
);
}).length;
/*
A review is complete if all scores either:
1) have a score not equal to NR (default score when created)
2) have an NR score, but notes were added
*/
const isIncomplete = score => {
return _.includes(NR_KEYS, score.score) && !h.hasInnerText(score.notes);
};
return this.editableScores.filter(isIncomplete).length;
}

updateRobScore(score, riskofbias, overrideOptions) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/shared/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ const helpers = {
// wrap text with html tag to ensure it is a valid jQuery selector expression
// then return whether there is text content
return (
$(`<p>${text}</p>`)
$(`<div>${text}</div>`)
.text()
.trim().length > 0
);
Expand Down
1 change: 1 addition & 0 deletions hawc/apps/riskofbias/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class RiskOfBiasResponses(models.IntegerChoices):
SCORE_CHOICES_MAP: Dict[int, str] = {k: v for k, v in SCORE_CHOICES}

NA_SCORES: Tuple[int, ...] = (10, 20)
NR_SCORES: Tuple[int, ...] = (12, 22)

SCORE_SYMBOLS: Dict[int, str] = {
0: "━",
Expand Down
18 changes: 18 additions & 0 deletions hawc/apps/riskofbias/migrations/0026_fix_blank_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import migrations

from ..constants import NR_SCORES


def forwards_func(apps, schema_editor):
RiskOfBiasScore = apps.get_model("riskofbias", "RiskOfBiasScore")
RiskOfBiasScore.objects.filter(score__in=NR_SCORES, notes="<p> </p>").update(notes="<p>-</p>")


def reverse_func(apps, schema_editor):
RiskOfBiasScore = apps.get_model("riskofbias", "RiskOfBiasScore")
RiskOfBiasScore.objects.filter(score__in=NR_SCORES, notes="<p>-</p>").update(notes="<p> </p>")


class Migration(migrations.Migration):
dependencies = [("riskofbias", "0025_alter_riskofbias_study")]
operations = [migrations.RunPython(forwards_func, reverse_code=reverse_func)]
20 changes: 10 additions & 10 deletions hawc/apps/riskofbias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,18 @@ def deactivate(self):
self.save()

@property
def is_complete(self):
def is_complete(self) -> bool:
"""
The rich text editor used for notes input adds HTML tags even if input
is empty, so HTML needs to be stripped out.
A review is complete if all scores either:
1) have a score not equal to NR (default score when created)
2) have an NR score, but notes were added
"""
return all(
[
len(strip_tags(score.notes).strip()) > 0
for score in self.scores.all()
if score.score not in constants.NA_SCORES
]
)
incomplete = [
item
for item in self.scores.all()
if item.score in constants.NR_SCORES and len(strip_tags(item.notes).strip()) == 0
]
return len(incomplete) == 0

@property
def study_reviews_complete(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/api/api-summary-table-set-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"riskofbias_id": 3,
"score_id": 6,
"score_label": "base",
"score_notes": "<p>Fine, but subsets are imprortant</p>",
"score_notes": "<p>Fine, but subsets are important</p>",
"score_score": 16,
"study_id": 1
},
Expand Down
2 changes: 1 addition & 1 deletion tests/data/fixtures/db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4197,7 +4197,7 @@
label: base
score: 16
bias_direction: 2
notes: <p>Fine, but subsets are imprortant</p>
notes: <p>Fine, but subsets are important</p>
- model: riskofbias.riskofbiasscore
pk: 7
fields:
Expand Down

0 comments on commit d094598

Please sign in to comment.