def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() main_dict = {None: None} q10_dict = {None: None} for option in range(0, 5): main_dict[option] = ( str(option) + " — " + self.wxstring(req, "main_option" + str(option)) ) q10_dict[option] = ( str(option) + " — " + self.wxstring(req, "q10_option" + str(option)) ) q_a = "" for q in range(1, 10): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict(main_dict, getattr(self, "q" + str(q))), ) q_a += ( tr_qa( self.wxstring(req, "q10_s"), get_from_dict(q10_dict, self.q10) ) + tr_qa( self.wxstring(req, "q11_s"), get_yes_no_none(req, self.q11) ) + tr_qa( self.wxstring(req, "q12_s"), get_yes_no_none(req, self.q12) ) ) return f"""
def get_rows(self, req: CamcopsRequest, field_name: str) -> str: rows = "" question_text = self.xstring(req, f"q_{field_name}") answer = getattr(self, field_name) answer_text = answer if answer is not None and (field_name in self.MULTI_CHOICE_FIELD_NAMES): answer_text = self.xstring(req, f"{field_name}_{answer}") rows += tr_qa(question_text, answer_text) if answer and field_name in self.DETAILS_FIELDS: details_field_name = self.DETAILS_FIELDS[field_name] details_question_text = self.xstring(req, f"q_{details_field_name}") details_answer = getattr(self, details_field_name) rows += tr_qa(details_question_text, details_answer) if field_name == self.FN_DIAGNOSIS_DATE: rows += tr_qa( self.xstring(req, f"q_{self.FN_DIAGNOSIS_DATE_APPROXIMATE}"), getattr(self, self.FN_DIAGNOSIS_DATE_APPROXIMATE), ) return rows
def get_task_html(self, req: CamcopsRequest) -> str: if self.rating is not None: r = "{}. {}".format(self.rating, self.get_rating_text(req)) else: r = None h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {service} {rating} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), service=tr_qa(req.wappstring("satis_service_being_rated"), self.service), rating=tr_qa(self.wxstring(req, "q"), r), ) return h
def get_task_html(self, req: CamcopsRequest) -> str: rows = [ tr_qa( self.wxstring(req, f"q_{self.FN_CONTACT_PREFERENCE}_short"), self.get_contact_preference_answer(req), ), tr_qa( self.wxstring(req, f"q_{self.FN_CONTACT_BY_EMAIL}_short"), self.get_contact_by_email_answer(req), ), tr_qa( self.wxstring(req, f"q_{self.FN_RESEARCH_OPT_OUT}_short"), self.get_research_opt_out_answer(req), ), ] html = f""" <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {self.get_is_complete_tr(req)} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {''.join(rows)} </table> """ return html
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_cutoff = score >= 8 q1_dict = {None: None} q2_dict = {None: None} q3_to_8_dict = {None: None} q9_to_10_dict = {None: None} for option in range(0, 5): q1_dict[option] = (str(option) + " – " + self.wxstring(req, "q1_option" + str(option))) q2_dict[option] = (str(option) + " – " + self.wxstring(req, "q2_option" + str(option))) q3_to_8_dict[option] = ( str(option) + " – " + self.wxstring(req, "q3to8_option" + str(option))) if option != 1 and option != 3: q9_to_10_dict[option] = ( str(option) + " – " + self.wxstring(req, "q9to10_option" + str(option))) q_a = tr_qa(self.wxstring(req, "q1_s"), get_from_dict(q1_dict, self.q1)) q_a += tr_qa(self.wxstring(req, "q2_s"), get_from_dict(q2_dict, self.q2)) for q in range(3, 8 + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict(q3_to_8_dict, getattr(self, "q" + str(q))), ) q_a += tr_qa(self.wxstring(req, "q9_s"), get_from_dict(q9_to_10_dict, self.q9)) q_a += tr_qa(self.wxstring(req, "q10_s"), get_from_dict(q9_to_10_dict, self.q10)) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for i in range(1, self.N_QUESTIONS + 1): nstr = str(i) answers = { None: None, 1: "1 – " + self.wxstring(req, "q" + nstr + "_o1"), 2: "2 – " + self.wxstring(req, "q" + nstr + "_o2"), 3: "3 – " + self.wxstring(req, "q" + nstr + "_o3"), 4: "4 – " + self.wxstring(req, "q" + nstr + "_o4"), 5: "5 – " + self.wxstring(req, "q" + nstr + "_o5"), } q_a += tr_qa( nstr + ". " + self.wxstring(req, "q" + nstr + "_h"), get_from_dict(answers, getattr(self, "q" + str(i))), ) q_a += tr_qa( ("Self-rated health on a visual analogue scale (0–100) " "<sup>[2]</sup>"), self.health_vas, ) return f"""
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: c_dict = { 0: "0 — " + self.wxstring(req, "a0_choice"), 1: "1 — " + self.wxstring(req, "a1_choice"), 2: "2 — " + self.wxstring(req, "a2_choice"), } s_dict = { 0: "0 — " + self.wxstring(req, "a0_satisfaction"), 1: "1 — " + self.wxstring(req, "a1_satisfaction"), 2: "2 — " + self.wxstring(req, "a2_satisfaction"), 3: "3 — " + self.wxstring(req, "a3_satisfaction"), 4: "4 — " + self.wxstring(req, "a4_satisfaction"), } q_a = "" for i in range(1, self.N_CHOICE_QUESTIONS + 1): nstr = str(i) q_a += tr_qa( self.wxstring(req, "q" + nstr + "_choice"), get_from_dict(c_dict, getattr(self, "q" + nstr + "_choice")), ) q_a += tr_qa( self.wxstring(req, "q1_satisfaction"), get_from_dict(s_dict, self.q1_satisfaction), ) q_a += tr_qa( self.wxstring(req, "q2_satisfaction"), self.q2_satisfaction, default="", ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: scorer = self.get_score() quality = tr_qa( self.wxstring(req, "quality_of_attachment_score") + f" [{scorer.quality_min}–{scorer.quality_max}]", scorer.quality_score, ) time = tr_qa( self.wxstring(req, "time_in_attachment_mode_score") + f" [{scorer.time_min}–{scorer.time_max}]", scorer.time_score, ) globalscore = tr_qa( self.wxstring(req, "global_attachment_score") + f" [{scorer.global_min}–{scorer.global_max}]", scorer.global_score, ) lines = [] # type: List[str] for q in range(1, self.N_QUESTIONS + 1): question = f"{q}. " + self.wxstring(req, f"q{q}_q") value = getattr(self, self.FN_QPREFIX + str(q)) answer = None if (value is not None and self.MIN_SCORE_PER_Q <= value <= self.MAX_SCORE_PER_Q): answer = f"{value}: " + self.wxstring(req, f"q{q}_a{value}") lines.append(tr_qa(question, answer)) q_a = "".join(lines) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: if self.achieved is not None: achieved = "{}. {}".format(self.achieved, self.get_achieved_text(req)) else: achieved = None h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {aim} {achieved} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), aim=tr_qa(self.wxstring(req, "q_aim"), ws.webify(self.aim)), achieved=tr_qa(self.wxstring(req, "q_achieved"), achieved), ) 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: 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: 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: 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() 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: 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: 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, 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)) # noqa q_a += tr_qa(self.wxstring(req, "q2"), get_from_dict(main_dict, self.q2)) # noqa q_a += tr_qa(self.wxstring(req, "q3"), get_from_dict(main_dict, self.q3)) # noqa q_a += tr_qa(self.wxstring(req, "q4"), get_from_dict(q4_dict, self.q4)) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {positive} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] Negative if Q1 = 0. Positive if Q1 ≥ 3. Otherwise positive if total score ≥ 3. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score"), answer(self.total_score()) + " / {}".format(self.MAX_SCORE)), positive=tr_qa( self.wxstring(req, "positive") + " <sup>[1]</sup>", get_yes_no(req, self.is_positive())), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for i in range(1, self.N_QUESTIONS + 1): nstr = str(i) answers = { None: None, 1: "1 – " + self.wxstring(req, "q" + nstr + "_o1"), 2: "2 – " + self.wxstring(req, "q" + nstr + "_o2"), 3: "3 – " + self.wxstring(req, "q" + nstr + "_o3"), 4: "4 – " + self.wxstring(req, "q" + nstr + "_o4"), 5: "5 – " + self.wxstring(req, "q" + nstr + "_o5"), } q_a += tr_qa(nstr + ". " + self.wxstring(req, "q" + nstr + "_h"), get_from_dict(answers, getattr(self, "q" + str(i)))) q_a += tr_qa(("Self-rated health on a visual analogue scale (0–100) " "<sup>[2]</sup>"), self.health_vas) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {mcq_score} {vis_score} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] This is a string of digits, not a directly meaningful number. Each digit corresponds to a question. A score of 1 indicates no problems in any given dimension. 5 indicates extreme problems. Missing values are coded as 9. [2] This is the visual analogue health score, with missing values coded as 999. </div> """.format(CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), mcq_score=tr_qa("Health state code <sup>[1]</sup>", self.get_health_state_code()), vis_score=tr_qa( "Visual analogue scale summary number <sup>[2]</sup>", self.get_vis_score_or_999()), q_a=q_a) return h
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 0: "0 — " + self.wxstring(req, "old_option0"), 1: "1 — " + self.wxstring(req, "old_option1"), 2: "2 — " + self.wxstring(req, "old_option2"), 3: "3 — " + self.wxstring(req, "old_option3"), 4: "4 — " + self.wxstring(req, "old_option4"), 5: "5 — " + self.wxstring(req, "old_option5"), 6: "6 — " + self.wxstring(req, "old_option6"), 7: "7 — " + self.wxstring(req, "old_option7"), } q19_dict = { None: None, 1: self.wxstring(req, "q19_option1"), 2: self.wxstring(req, "q19_option2"), 3: self.wxstring(req, "q19_option3"), 4: self.wxstring(req, "q19_option4"), 5: self.wxstring(req, "q19_option5"), 6: self.wxstring(req, "q19_option6"), 7: self.wxstring(req, "q19_option7"), } q20_dict = { None: None, 0: self.wxstring(req, "q20_option0"), 1: self.wxstring(req, "q20_option1"), 2: self.wxstring(req, "q20_option2"), 3: self.wxstring(req, "q20_option3"), 4: self.wxstring(req, "q20_option4"), 5: self.wxstring(req, "q20_option5"), 6: self.wxstring(req, "q20_option6"), 7: self.wxstring(req, "q20_option7"), } q_a = "" for i in range(1, Bprs.NQUESTIONS - 1): # only does 1-18 q_a += tr_qa( self.wxstring(req, "q" + str(i) + "_title"), get_from_dict(main_dict, getattr(self, "q" + str(i))), ) q_a += tr_qa(self.wxstring(req, "q19_title"), get_from_dict(q19_dict, self.q19)) q_a += tr_qa(self.wxstring(req, "q20_title"), get_from_dict(q20_dict, self.q20)) total_score = tr( req.sstring(SS.TOTAL_SCORE) + f" (0–{self.MAX_SCORE}; 18–{self.MAX_SCORE} if all rated) " "<sup>[1]</sup>", answer(self.total_score()), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() severity = self.severity(req) answer_dicts = [] for q in range(1, self.NQUESTIONS + 1): d = {None: None} for option in range(0, 5): if q == 6 and option > 2: continue d[option] = self.wxstring( req, "q" + str(q) + "_option" + str(option)) answer_dicts.append(d) q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict(answer_dicts[q - 1], getattr(self, "q" + str(q))), ) return """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {severity} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="30%">Question</th> <th width="70%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] ≥20 severe, ≥12 moderate, ≥4 mild, <4 none. </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), ), severity=tr_qa( self.wxstring(req, "severity") + " <sup>[1]</sup>", severity), q_a=q_a, )
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() answer_dict = {None: None} for option in range(self.N_ANSWERS): answer_dict[option] = str(option) + " – " + \ self.wxstring(req, "a" + str(option)) q_a = "" for q in range(1, self.N_QUESTIONS): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict(answer_dict, getattr(self, "q" + str(q)))) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {depression_or_risk_of} {provisional_diagnosis} </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] Presence of depression (or depression risk) is indicated by a score ≥ 16 [2] Diagnostic criteria described at <a href="https://cesd-r.com/cesdr/">https://cesd-r.com/cesdr/</a> </div> """.format( # noqa CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr_qa( "{} (0–60)".format(req.wappstring("total_score")), score), depression_or_risk_of=tr_qa( self.wxstring(req, "depression_or_risk_of") + "? <sup>[1]</sup>", get_yes_no(req, self.has_depression_risk())), provisional_diagnosis=tr( 'Provisional diagnosis <sup>[2]</sup>', self.wxstring( req, "category_" + str(self.get_depression_category()))), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: score_dict = { 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"), } rows = "" for i in range(1, self.N_SCORED_QUESTIONS + 1): q_field = "q" + str(i) question_cell = "{}. {}".format(i, self.wxstring(req, q_field)) answer_cell = get_from_dict(score_dict, getattr(self, q_field)) rows += tr_qa(question_cell, answer_cell) rows += tr_qa( "16. " + self.wxstring(req, "q16"), get_yes_no_unknown(req, "q16") ) html = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {rows} </table> <div class="{CssClass.FOOTNOTES}"> [1] Sum for questions 1–15. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.sstring(SS.TOTAL_SCORE) + " <sup>[1]</sup>", answer(self.total_score()) + f" / {self.MAX_SCORE_MAIN}", ), rows=rows, ) return html
def addqa(_fieldname: str, _valuedict: Dict[int, str]) -> None: xstringname = _fieldname + "_q" q_a_list.append( tr_qa( self.xstring(req, xstringname), # not wxstring get_from_dict(_valuedict, getattr(self, _fieldname)), ))
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: dp = 6 qlines = [] # type: List[str] for t in self.trials: info = t.info() qlines.append( tr_qa( f"{t.trial}. {info.question(req)} " f"<i>(k<sub>indiff</sub> = " f"{round(info.k_indifference(), dp)})</i>", info.answer(req), )) q_a = "\n".join(qlines) results = self.all_choice_results() k_kirby = self.k_kirby(results) if k_kirby is None: inv_k_kirby = None else: inv_k_kirby = int(round(1 / k_kirby)) # round to int # ... you'd think the int() was unnecessary but it is needed k_kirby = round(k_kirby, dp) k_wileyto = self.k_wileyto(results) if k_wileyto is None: inv_k_wileyto = None else: inv_k_wileyto = int(round(1 / k_wileyto)) # round to int k_wileyto = round(k_wileyto, dp) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: rows = "" for field_name in self.MANDATORY_FIELD_NAMES: question_text = self.xstring(req, f"q_{field_name}") answer_text = self.get_answer_text(req, field_name) rows += tr_qa(question_text, answer_text) html = f""" <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {self.get_is_complete_tr(req)} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {rows} </table> """ return html
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() q_a = "" for f in FIELDNAMES: v = getattr(self, f) q_a += tr_qa(self.wxstring(req, f), get_yes_no_unknown(req, v)) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for attrname, column in gen_camcops_columns(self): if attrname.startswith("clinician_"): # not the most elegant! continue question = column.comment value = getattr(self, attrname) q_a += tr_qa(question, value) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="30%">Answer</th> </tr> {q_a} </table> {DATA_COLLECTION_ONLY_DIV} """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), q_a=q_a, DATA_COLLECTION_ONLY_DIV=DATA_COLLECTION_ONLY_DIV, ) return h
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"""