def get_task_html(self, req: CamcopsRequest) -> str: target_symptoms = "" for col in self.TARGET_COLUMNS: target_symptoms += tr(col.comment, answer(getattr(self, col.name))) q_a = "" for qi in self.QINFO: fieldname = "q" + qi[0] value = getattr(self, fieldname) q_a += tr( self.wxstring(req, fieldname + "_title"), answer(self.wxstring(req, fieldname + "_a" + str(value), value) if value is not None else None) ) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {complete_tr} <tr> <td>Total score</td> <td>{total_score} / {mt}</td> </td> <tr> <td>Obsession score</td> <td>{obsession_score} / {mo}</td> </td> <tr> <td>Compulsion score</td> <td>{compulsion_score} / {mc}</td> </td> </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Target symptom</th> <th width="50%">Detail</th> </tr> {target_symptoms} </table> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {q_a} </table> {DATA_COLLECTION_UNLESS_UPGRADED_DIV} """.format( CssClass=CssClass, complete_tr=self.get_is_complete_tr(req), total_score=answer(self.total_score()), mt=self.MAX_TOTAL, obsession_score=answer(self.obsession_score()), mo=self.MAX_OBS, compulsion_score=answer(self.compulsion_score()), mc=self.MAX_COM, target_symptoms=target_symptoms, q_a=q_a, DATA_COLLECTION_UNLESS_UPGRADED_DIV=DATA_COLLECTION_UNLESS_UPGRADED_DIV, # noqa ) return h
def get_html_table_row(self) -> str: return tr( self.seqnum, answer(ws.webify(self.code)), answer(ws.webify(self.description)), answer(ws.webify(self.comment)), )
def answer_row_html(self, req: CamcopsRequest, q: int) -> str: qtext = self.wxstring(req, "q" + str(q)) v = getattr(self, "q" + str(q)) atext = self.answer_text(req, q, v) s = self.recode(q) return tr(qtext, answer(v) + ": " + answer(atext), answer(s, formatter_answer=identity))
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() severity = self.severity(req) answer_dicts_dict = {} for q in self.SCORED_QUESTIONS: d = {None: None} for option in range(0, 8): if option > 4 and q == "q10": continue d[option] = self.wxstring(req, q + "_option" + str(option)) answer_dicts_dict[q] = d q_a = "" for q in range(1, Ciwa.NSCOREDQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict(answer_dicts_dict["q" + str(q)], getattr(self, "q" + str(q)))) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {severity} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="35%">Question</th> <th width="65%">Answer</th> </tr> {q_a} {subhead_vitals} {t} {hr} {bp} {rr} </table> <div class="{CssClass.FOOTNOTES}"> [1] Total score ≥15 severe, ≥8 moderate, otherwise mild/minimal. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / {}".format(self.MAX_SCORE)), severity=tr_qa( self.wxstring(req, "severity") + " <sup>[1]</sup>", severity), q_a=q_a, subhead_vitals=subheading_spanning_two_columns( self.wxstring(req, "vitals_title")), t=tr_qa(self.wxstring(req, "t"), self.t), hr=tr_qa(self.wxstring(req, "hr"), self.hr), bp=tr(self.wxstring(req, "bp"), answer(self.sbp) + " / " + answer(self.dbp)), rr=tr_qa(self.wxstring(req, "rr"), self.rr), ) return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_cutoff_1 = score >= 6 exceeds_cutoff_2 = score >= 11 main_dict = { None: None, "Y": req.sstring(SS.YES), "N": req.sstring(SS.NO), } q_a = "" for q in range(1, Dast.NQUESTIONS + 1): q_a += tr( self.wxstring(req, "q" + str(q)), answer(get_from_dict(main_dict, getattr(self, "q" + str(q)))) + " — " + answer(str(self.get_score(q))), ) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {exceeds_standard_cutoff_1} {exceeds_standard_cutoff_2} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="80%">Question</th> <th width="20%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.COPYRIGHT}"> DAST: Copyright © Harvey A. Skinner and the Centre for Addiction and Mental Health, Toronto, Canada. Reproduced here under the permissions granted for NON-COMMERCIAL use only. You must obtain permission from the copyright holder for any other use. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(score) + f" / {self.NQUESTIONS}", ), exceeds_standard_cutoff_1=tr_qa( self.wxstring(req, "exceeds_standard_cutoff_1"), get_yes_no(req, exceeds_cutoff_1), ), exceeds_standard_cutoff_2=tr_qa( self.wxstring(req, "exceeds_standard_cutoff_2"), get_yes_no(req, exceeds_cutoff_2), ), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: min_score = 0 max_score = 3 crippled = not self.extrastrings_exist(req) a = self.anxiety_score() d = self.depression_score() h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {is_complete_tr} <tr> <td>{sa}</td><td>{a} / {maxa}</td> </tr> <tr> <td>{sd}</td><td>{d} / 21</td> </tr> </table> </div> <div class="{CssClass.EXPLANATION}"> All questions are scored from 0–3 (0 least symptomatic, 3 most symptomatic). </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> """.format( CssClass=CssClass, is_complete_tr=self.get_is_complete_tr(req), sa=req.wappstring("hads_anxiety_score"), a=answer(a), maxa=self.MAX_ANX_SCORE, sd=req.wappstring("hads_depression_score"), d=answer(d), ) for n in range(1, self.NQUESTIONS + 1): if crippled: q = "HADS: Q{}".format(n) else: q = "Q{}. {}".format( n, self.wxstring(req, "q" + str(n) + "_stem")) if n in self.ANXIETY_QUESTIONS: q += " (A)" if n in self.DEPRESSION_QUESTIONS: q += " (D)" v = getattr(self, "q" + str(n)) if crippled or v is None or v < min_score or v > max_score: a = v else: a = "{}: {}".format(v, self.wxstring(req, "q{}_a{}".format(n, v))) h += tr_qa(q, a) h += """ </table> """ + DATA_COLLECTION_UNLESS_UPGRADED_DIV return h
def get_task_html(self, req: CamcopsRequest) -> str: option_dict = {None: None} for a in range(self.MIN_SCORE, self.MAX_SCORE + 1): option_dict[a] = req.wappstring("iesr_a" + str(a)) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {complete_tr} <tr> <td>Total score</td> <td>{total} / {maxtotal}</td> </td> <tr> <td>Avoidance score</td> <td>{avoidance} / {maxavoidance}</td> </td> <tr> <td>Intrusion score</td> <td>{intrusion} / {maxintrusion}</td> </td> <tr> <td>Hyperarousal score</td> <td>{hyperarousal} / {maxhyperarousal}</td> </td> </table> </div> <table class="{CssClass.TASKDETAIL}"> {tr_event} </table> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="75%">Question</th> <th width="25%">Answer (0–4)</th> </tr> """.format( CssClass=CssClass, complete_tr=self.get_is_complete_tr(req), total=answer(self.total_score()), maxtotal=self.MAX_TOTAL, avoidance=answer(self.avoidance_score()), maxavoidance=self.MAX_AVOIDANCE, intrusion=answer(self.intrusion_score()), maxintrusion=self.MAX_INTRUSION, hyperarousal=answer(self.hyperarousal_score()), maxhyperarousal=self.MAX_HYPERAROUSAL, tr_event=tr_qa(req.wappstring("event"), self.event), ) for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) fa = ("{}: {}".format(a, get_from_dict(option_dict, a)) if a is not None else None) h += tr(self.wxstring(req, "q" + str(q)), answer(fa)) h += """ </table> """ + DATA_COLLECTION_UNLESS_UPGRADED_DIV return h
def get_task_html(self, req: CamcopsRequest) -> str: h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {complete_tr} <tr> <td>Endorsed</td> <td>{e} / 12</td> </td> <tr> <td>Severity score</td> <td>{s} / 36</td> </td> <tr> <td>Distress score</td> <td>{d} / 60</td> </td> </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="40%">Question</th> <th width="20%">Endorsed</th> <th width="20%">Severity (patient)</th> <th width="20%">Distress (carer)</th> </tr> """.format( CssClass=CssClass, complete_tr=self.get_is_complete_tr(req), e=self.n_endorsed(), s=self.severity_score(), d=self.distress_score(), ) for q in range(1, self.NQUESTIONS + 1): qstr = str(q) e = getattr(self, ENDORSED + qstr) s = getattr(self, SEVERITY + qstr) d = getattr(self, DISTRESS + qstr) qtext = "<b>{}:</b> {}".format( self.wxstring(req, "t" + qstr), self.wxstring(req, "q" + qstr), ) etext = get_yes_no_unknown(req, e) if e: stext = self.wxstring(req, "severity_{}".format(s), s, provide_default_if_none=False) dtext = self.wxstring(req, "distress_{}".format(d), d, provide_default_if_none=False) else: stext = "" dtext = "" h += tr(qtext, answer(etext), answer(stext), answer(dtext)) h += """ </table> """ + DATA_COLLECTION_UNLESS_UPGRADED_DIV return h
def get_task_html(self, req: CamcopsRequest) -> str: answers = { None: None, 0: "0 — " + self.wxstring(req, "a0"), 1: "1 — " + self.wxstring(req, "a1"), 2: "2 — " + self.wxstring(req, "a2"), 3: "3 — " + self.wxstring(req, "a3"), 4: "4 — " + self.wxstring(req, "a4"), } subscore_html = "" answer_html = "" for info in self.GROUPS: heading = self.wxstring(req, info.heading_xstring_name) subscore = info.subscore(self) subscore_html += tr(heading, (answer(round(subscore, DISPLAY_DP)) + " / {}".format(info.max_score))) answer_html += subheading_spanning_two_columns(heading) for q in info.fieldnames: if q == self.OPTIONAL_Q: # insert additional row answer_html += tr_qa(self.xstring(req, "prefer_no_answer"), self.ignore_s_q7) answer_val = getattr(self, q) answer_html += tr_qa(self.wxstring(req, q), get_from_dict(answers, answer_val)) tscore = round(self.total_score(), DISPLAY_DP) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {subscore_html} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {answer_html} """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score"), answer(tscore) + " / {}".format(self.MAX_SCORE_TOTAL)), subscore_html=subscore_html, answer_html=answer_html, ) h += """ </table> """ return h
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for q in ALL: q_a += tr( f"{q}. " + self.wxstring(req, "q" + str(q)) + " (<i>" + self.question_category(q) + "</i>)", answer(self.get_frequency(q)), answer( self.get_distress_score(q) if self.endorsed(q) else None, default=str(MIN_SCORE_PER_Q), ), ) raw_overall = tr( f"Overall <sup>[1]</sup> ({ALL_MIN}–{ALL_MAX})", self.frequency_score(ALL), self.distress_score(ALL), ) raw_positive = tr( f"Positive symptoms ({POS_MIN}–{POS_MAX})", self.frequency_score(POSITIVE), self.distress_score(POSITIVE), ) raw_negative = tr( f"Negative symptoms ({NEG_MIN}–{NEG_MAX})", self.frequency_score(NEGATIVE), self.distress_score(NEGATIVE), ) raw_depressive = tr( f"Depressive symptoms ({DEP_MIN}–{DEP_MAX})", self.frequency_score(DEPRESSIVE), self.distress_score(DEPRESSIVE), ) weighted_overall = tr( f"Overall ({len(ALL)} questions)", ws.number_to_dp(self.weighted_frequency_score(ALL), DP), ws.number_to_dp(self.weighted_distress_score(ALL), DP), ) weighted_positive = tr( f"Positive symptoms ({len(POSITIVE)} questions)", ws.number_to_dp(self.weighted_frequency_score(POSITIVE), DP), ws.number_to_dp(self.weighted_distress_score(POSITIVE), DP), ) weighted_negative = tr( f"Negative symptoms ({len(NEGATIVE)} questions)", ws.number_to_dp(self.weighted_frequency_score(NEGATIVE), DP), ws.number_to_dp(self.weighted_distress_score(NEGATIVE), DP), ) weighted_depressive = tr( f"Depressive symptoms ({len(DEPRESSIVE)} questions)", ws.number_to_dp(self.weighted_frequency_score(DEPRESSIVE), DP), ws.number_to_dp(self.weighted_distress_score(DEPRESSIVE), DP), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: h = f""" <table class="{CssClass.TASKDETAIL}"> <tr> <th width="55%">Symptom</th> <th width="15%">Current</th> <th width="15%">Past</th> <th width="15%">Principal</th> </tr> """ for group in self.GROUPS: h += subheading_spanning_four_columns( self.wxstring(req, self.SC_PREFIX + group)) for item in self.ITEMS: if not item.startswith(group): continue h += tr( self.wxstring(req, self.SC_PREFIX + item), answer( get_ternary( getattr(self, item + self.SUFFIX_CURRENT), value_true="Current", value_false="", value_none="", )), answer( get_ternary( getattr(self, item + self.SUFFIX_PAST), value_true="Past", value_false="", value_none="", )), answer( get_ternary( getattr(self, item + self.SUFFIX_PRINCIPAL), value_true="Principal", value_false="", value_none="", )), ) if item.endswith(self.SUFFIX_OTHER): h += f""" <tr> <td><i>Specify:</i></td> <td colspan="3">{ answer(getattr(self, item + self.SUFFIX_DETAIL), "")}</td> </tr> """ h += f""" </table> {DATA_COLLECTION_UNLESS_UPGRADED_DIV} """ return h
def get_question_rows(first, last): html = "" for q in range(first, last + 1): f = getattr(self, "frequency" + str(q)) d = getattr(self, "distress" + str(q)) fa = (f"{f}: {get_from_dict(freq_dict, f)}" if f is not None else None) da = (f"{d}: {get_from_dict(distress_dict, d)}" if d is not None else None) html += tr(self.wxstring(req, "q" + str(q)), answer(fa), answer(da)) return html
def get_task_html(self, req: CamcopsRequest) -> str: tto_qol = self.get_tto_qol() rs_qol = self.get_rs_qol() mean_qol = mean([tto_qol, rs_qol]) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {mean_qol} </table> </div> <div class="{CssClass.EXPLANATION}"> Quality of life (QoL) has anchor values of 0 (none) and 1 (perfect health), and can be asked about in several ways. </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="33%">Scale</th> <th width="33%">Answer</th> <td width="33%">Implied QoL</th> </tr> {tto} {rs} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), mean_qol=tr( "Mean QoL", answer( ws.number_to_dp(mean_qol, DP, default=None), formatter_answer=identity, ), ), tto=tr( self.wxstring(req, "tto_q_s"), answer(ws.number_to_dp(self.tto, DP, default=None)), answer( ws.number_to_dp(tto_qol, DP, default=None), formatter_answer=identity, ), ), rs=tr( self.wxstring(req, "rs_q_s"), answer(ws.number_to_dp(self.rs, DP, default=None)), answer( ws.number_to_dp(rs_qol, DP, default=None), formatter_answer=identity, ), ), ) return h
def get_task_html(self, req: CamcopsRequest) -> str: target_symptoms = "" for col in self.TARGET_COLUMNS: target_symptoms += tr(col.comment, answer(getattr(self, col.name))) q_a = "" for qi in self.QINFO: fieldname = "q" + qi[0] value = getattr(self, fieldname) q_a += tr( self.wxstring(req, fieldname + "_title"), answer( self.wxstring(req, fieldname + "_a" + str(value), value ) if value is not None else None), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() likelihood = self.likelihood(req) main_dict = { None: None, "Y": req.sstring(SS.YES), "N": req.sstring(SS.NO), } q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr( self.wxstring(req, "q" + str(q)), answer(get_from_dict(main_dict, getattr(self, "q" + str(q)))) + " — " + str(self.get_score(q)), ) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {problem_likelihood} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="80%">Question</th> <th width="20%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] Total score ≥3 probable, ≥2 possible, 0–1 unlikely. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(score) + f" / {self.NQUESTIONS}", ), problem_likelihood=tr_qa( self.wxstring(req, "problem_likelihood") + " <sup>[1]</sup>", likelihood, ), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_cutoff = score >= 2 q_a = "" for q in range(1, Cage.NQUESTIONS + 1): q_a += tr_qa( str(q) + " — " + self.wxstring(req, "q" + str(q)), getattr(self, "q" + str(q))) # answer is itself Y/N/NULL # noqa h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {over_threshold} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="30%">Answer</th> </tr> {q_a} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / {}".format(self.NQUESTIONS)), over_threshold=tr_qa(self.wxstring(req, "over_threshold"), get_yes_no(req, exceeds_cutoff)), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() severity = self.severity(req) answer_dicts_dict = {} for q in self.SCORED_QUESTIONS: d = {None: None} for option in range(0, 8): if option > 4 and q == "q10": continue d[option] = self.wxstring(req, q + "_option" + str(option)) answer_dicts_dict[q] = d q_a = "" for q in range(1, Ciwa.NSCOREDQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict( answer_dicts_dict["q" + str(q)], getattr(self, "q" + str(q)), ), ) tr_total_score = tr(req.sstring(SS.TOTAL_SCORE), answer(score) + f" / {self.MAX_SCORE}") tr_severity = tr_qa( self.wxstring(req, "severity") + " <sup>[1]</sup>", severity) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() severity = self.severity(req) answer_dict = {None: None} for option in range(0, 4): answer_dict[option] = (str(option) + " — " + self.wxstring(req, "a" + str(option))) q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q)), get_from_dict(answer_dict, getattr(self, "q" + str(q))), ) return """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {anxiety_severity} </table> </div> <div class="{CssClass.EXPLANATION}"> Ratings are over the last 2 weeks. </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] ≥15 severe, ≥10 moderate, ≥5 mild. Score ≥10 identifies: generalized anxiety disorder with sensitivity 89%, specificity 82% (Spitzer et al. 2006, PubMed ID 16717171); panic disorder with sensitivity 74%, specificity 81% (Kroenke et al. 2010, PMID 20633738); social anxiety with sensitivity 72%, specificity 80% (Kroenke et al. 2010); post-traumatic stress disorder with sensitivity 66%, specificity 81% (Kroenke et al. 2010). The majority of evidence contributing to these figures comes from primary care screening studies. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(score) + " / {}".format(self.MAX_SCORE), ), anxiety_severity=tr( self.wxstring(req, "anxiety_severity") + " <sup>[1]</sup>", severity, ), q_a=q_a, )
def get_task_html(self, req: CamcopsRequest) -> str: h = f""" <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {self.get_is_complete_tr(req)} <tr> <td>Total score (16–80)</td> <td>{answer(self.total_score())}</td> </td> </table> </div> <div class="{CssClass.EXPLANATION}"> Anchor points are 1 = {self.wxstring(req, "anchor1")}, 5 = {self.wxstring(req, "anchor5")}. Questions {", ".join(str(x) for x in self.REVERSE_SCORE)} are reverse-scored. </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="15%">Answer (1–5)</th> <th width="15%">Score (1–5)</th> </tr> """ for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) score = self.score(q) h += tr(self.wxstring(req, "q" + str(q)), answer(a), score) h += """ </table> """ return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_threshold = self.exceeds_ross_threshold() main_dict = { None: None, "Y": req.sstring(SS.YES), "N": req.sstring(SS.NO), } q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr( self.wxstring(req, "q" + str(q)), (answer(get_from_dict(main_dict, getattr(self, "q" + str(q)))) + answer(" — " + str(self.get_score(q)))), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 0: "0 — " + self.wxstring(req, "q1to3_option0"), 1: "1 — " + self.wxstring(req, "q1to3_option1"), 2: "2 — " + self.wxstring(req, "q1to3_option2"), 3: "3 — " + self.wxstring(req, "q1to3_option3"), 4: "4 — " + self.wxstring(req, "q1to3_option4"), } q4_dict = { None: None, 0: "0 — " + self.wxstring(req, "q4_option0"), 2: "2 — " + self.wxstring(req, "q4_option2"), 4: "4 — " + self.wxstring(req, "q4_option4"), } q_a = tr_qa(self.wxstring(req, "q1"), get_from_dict(main_dict, self.q1)) q_a += tr_qa(self.wxstring(req, "q2"), get_from_dict(main_dict, self.q2)) q_a += tr_qa(self.wxstring(req, "q3"), get_from_dict(main_dict, self.q3)) q_a += tr_qa(self.wxstring(req, "q4"), get_from_dict(q4_dict, self.q4)) tr_total_score = tr( req.sstring(SS.TOTAL_SCORE), answer(self.total_score()) + f" / {self.MAX_SCORE}", ) tr_positive = tr_qa( self.wxstring(req, "positive") + " <sup>[1]</sup>", get_yes_no(req, self.is_positive()), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: def bprs_string(x: str) -> str: return req.wxstring("bprs", x) main_dict = { None: None, 0: "0 — " + bprs_string("old_option0"), 1: "1 — " + bprs_string("old_option1"), 2: "2 — " + bprs_string("old_option2"), 3: "3 — " + bprs_string("old_option3"), 4: "4 — " + bprs_string("old_option4"), 5: "5 — " + bprs_string("old_option5"), 6: "6 — " + bprs_string("old_option6"), 7: "7 — " + bprs_string("old_option7"), } q_a = "" for i in range(1, self.NQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(i) + "_s"), get_from_dict(main_dict, getattr(self, "q" + str(i))), ) total_score = tr( req.sstring(SS.TOTAL_SCORE) + f" (0–{self.MAX_SCORE}; 24–{self.MAX_SCORE} if all rated)", answer(self.total_score()), ) return f"""
def four_column_row(q1: str, a1: Any, q2: str, a2: Any, default: str = "") -> str: return """ <tr> <td>{}</td><td>{}</td> <td>{}</td><td>{}</td> </tr> """.format( q1, answer(a1, default=default), q2, answer(a2, default=default), )
def get_task_html(self, req: CamcopsRequest) -> str: options_severity = { 3: self.wxstring(req, "severity_a3"), 2: self.wxstring(req, "severity_a2"), 1: self.wxstring(req, "severity_a1"), } q_a = [] # type: List[str] for q in range(1, N_QUESTIONS + 1): fieldname_main = qfieldname_main(q) q_main = self.wxstring(req, fieldname_main) v_main = getattr(self, fieldname_main) a_main = answer(get_yes_no_none(req, v_main)) if v_main: v_severity = getattr(self, qfieldname_severity(q)) a_severity = answer( f"{v_severity}: {options_severity.get(v_severity)}" if v_severity is not None else None ) v_frequency = getattr(self, qfieldname_frequency(q)) text_frequency = v_frequency if q in FREQUENCY_AS_PERCENT_QUESTIONS: note_frequency = "a" if v_frequency is not None: text_frequency = f"{v_frequency}%" else: note_frequency = "b" a_frequency = ( f"{answer(text_frequency)} <sup>[{note_frequency}]</sup>" if text_frequency is not None else answer(None) ) else: a_severity = "" a_frequency = "" q_a.append( f""" <tr> <td>{q_main}</td> <td>{a_main}</td> <td>{a_severity}</td> <td>{a_frequency}</td> </tr> """ ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: option_dict = {None: None} for a in range(self.MIN_PER_Q, self.MAX_PER_Q + 1): option_dict[a] = req.wappstring("wsas_a" + str(a)) q_a = "" for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) fa = get_from_dict(option_dict, a) if a is not None else None q_a += tr(self.wxstring(req, "q" + str(q)), answer(fa)) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {complete_tr} <tr> <td>Total score</td> <td>{total} / 40</td> </td> </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="75%">Question</th> <th width="25%">Answer</th> </tr> {retired_row} </table> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="75%">Question</th> <th width="25%">Answer (0–8)</th> </tr> {q_a} </table> {DATA_COLLECTION_UNLESS_UPGRADED_DIV} """.format( CssClass=CssClass, complete_tr=self.get_is_complete_tr(req), total=answer(self.total_score()), retired_row=tr_qa(self.wxstring(req, "q_retired_etc"), get_true_false(req, self.retired_etc)), q_a=q_a, DATA_COLLECTION_UNLESS_UPGRADED_DIV= DATA_COLLECTION_UNLESS_UPGRADED_DIV, # noqa ) return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() nsevere = self.num_severe() somatoform_likely = nsevere >= 3 severity = self.severity(req) answer_dict = {None: None} for option in range(0, 3): answer_dict[option] = str(option) + " – " + \ self.wxstring(req, "a" + str(option)) q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q)), get_from_dict(answer_dict, getattr(self, "q" + str(q)))) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {n_severe_symptoms} {exceeds_somatoform_cutoff} {symptom_severity} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="30%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] In males, maximum score is actually 28. [2] Questions with scores ≥2 are considered severe. [3] ≥3 severe symptoms. [4] Total score ≥15 severe, ≥10 moderate, ≥5 mild, otherwise none. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score") + " <sup>[1]</sup>", answer(score) + " / {}".format(self.MAX_TOTAL)), n_severe_symptoms=tr_qa( self.wxstring(req, "n_severe_symptoms") + " <sup>[2]</sup>", nsevere), exceeds_somatoform_cutoff=tr_qa( self.wxstring(req, "exceeds_somatoform_cutoff") + " <sup>[3]</sup>", get_yes_no(req, somatoform_likely)), symptom_severity=tr_qa( self.wxstring(req, "symptom_severity") + " <sup>[4]</sup>", severity), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: option_dict = {None: None} for a in range(self.MIN_PER_Q, self.MAX_PER_Q + 1): option_dict[a] = req.wappstring(AS.WSAS_A_PREFIX + str(a)) q_a = "" for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) fa = get_from_dict(option_dict, a) if a is not None else None q_a += tr(self.wxstring(req, "q" + str(q)), answer(fa)) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() q1_dict = {None: None} q2_dict = {None: None} q3_dict = {None: None} for option in range(0, 5): q1_dict[option] = str(option) + " – " + \ self.wxstring(req, "q1_option" + str(option)) if option == 0: # special! q2_dict[option] = str(option) + " – " + \ self.wxstring(req, "c_q2_option0") else: q2_dict[option] = str(option) + " – " + \ self.wxstring(req, "q2_option" + str(option)) q3_dict[option] = str(option) + " – " + \ self.wxstring(req, "q3to8_option" + str(option)) # noinspection PyUnresolvedReferences h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {q1} {q2} {q3} </table> <div class="{CssClass.COPYRIGHT}"> AUDIT: Copyright © World Health Organization. Reproduced here under the permissions granted for NON-COMMERCIAL use only. You must obtain permission from the copyright holder for any other use. AUDIT-C: presumed to have the same restrictions. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / 12"), q1=tr_qa(self.wxstring(req, "c_q1_question"), get_from_dict(q1_dict, self.q1)), q2=tr_qa(self.wxstring(req, "c_q2_question"), get_from_dict(q2_dict, self.q2)), q3=tr_qa(self.wxstring(req, "c_q3_question"), get_from_dict(q3_dict, self.q3)), ) return h
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 1: "1 — " + self.wxstring(req, "wemwbs_a1"), 2: "2 — " + self.wxstring(req, "wemwbs_a2"), 3: "3 — " + self.wxstring(req, "wemwbs_a3"), 4: "4 — " + self.wxstring(req, "wemwbs_a4"), 5: "5 — " + self.wxstring(req, "wemwbs_a5"), } q_a = "" for i in range(1, self.N_QUESTIONS + 1): nstr = str(i) q_a += tr_qa( self.wxstring(req, "wemwbs_q" + nstr), get_from_dict(main_dict, getattr(self, "q" + nstr)), ) h = """ <div class="{css_summary}"> <table class="{css_summary}"> {tr_is_complete} {tr_total_score} </table> </div> <div class="{css_explanation}"> Ratings are over the last 2 weeks. </div> <table class="{css_taskdetail}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {q_a} </table> <div class="{css_copyright}"> WEMWBS: from Tennant et al. (2007), <i>Health and Quality of Life Outcomes</i> 5:63, <a href="http://www.hqlo.com/content/5/1/63"> http://www.hqlo.com/content/5/1/63</a>; © 2007 Tennant et al.; distributed under the terms of the Creative Commons Attribution License. </div> """.format( css_summary=CssClass.SUMMARY, tr_is_complete=self.get_is_complete_tr(req), tr_total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(self.total_score()) + f" (range {self.MINTOTALSCORE}–{self.MAXTOTALSCORE})", ), css_explanation=CssClass.EXPLANATION, css_taskdetail=CssClass.TASKDETAIL, q_a=q_a, css_copyright=CssClass.COPYRIGHT, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for q in range(1, self.NQUESTIONS + 1): fieldname = "q" + str(q) qtext = self.wxstring(req, fieldname) # happens to be the same avalue = getattr(self, "q" + str(q)) atext = (self.wxstring(req, "q{}_{}".format(q, avalue)) if q is not None else None) score = self.score(fieldname) q_a += tr(qtext, answer(atext), score) return f"""