def buildOccupationalTable(self, exposures): colWidths = [1.7, 1, 1.7, 1.3, 2.0, 1.3] tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl") # write title txt = "Occupational exposure data" tbl.new_th(0, 0, txt, colspan=6) # write header tbl.new_th(1, 0, "Industry, country, year") tbl.new_th(1, 1, "Job/process") tbl.new_th(1, 2, "Mean, agent") tbl.new_th(1, 3, "Range") tbl.new_th(1, 4, "Comments/\nadditional data") tbl.new_th(1, 5, "References") row = 2 for exp in exposures: for res in exp["results"]: runs = [ tbl.new_run(exp["occupation"], newline=True, b=True), tbl.new_run( f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}', newline=False, ), ] tbl.new_td_run(row, 0, runs) txt = exp["occupationInfo"] or "" tbl.new_td_txt(row, 1, txt) txt = ( f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),' f' {res["agent"]}' ) tbl.new_td_txt(row, 2, txt) txt = res["exposureRangePrint"] tbl.new_td_txt(row, 3, txt) txt = exp["comments"] or "" tbl.new_td_txt(row, 4, txt) txt = exp["reference"]["name"] tbl.new_td_txt(row, 5, txt) row += 1 tbl.render(self.doc) self.doc.add_page_break()
def buildOccupationalTable(self, exposures): colWidths = [1.7, 1, 1.7, 1.3, 2.0, 1.3] tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl") # write title txt = "Occupational exposure data" tbl.new_th(0, 0, txt, colspan=6) # write header tbl.new_th(1, 0, "Industry, country, year") tbl.new_th(1, 1, "Job/process") tbl.new_th(1, 2, "Mean, agent") tbl.new_th(1, 3, "Range") tbl.new_th(1, 4, "Comments/\nadditional data") tbl.new_th(1, 5, "References") row = 2 for exp in exposures: for res in exp["results"]: runs = [ tbl.new_run(exp["occupation"], newline=True, b=True), tbl.new_run( f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}', newline=False, ), ] tbl.new_td_run(row, 0, runs) txt = exp["occupationInfo"] or "" tbl.new_td_txt(row, 1, txt) txt = ( f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),' f' {res["agent"]}') tbl.new_td_txt(row, 2, txt) txt = res["exposureRangePrint"] tbl.new_td_txt(row, 3, txt) txt = exp["comments"] or "" tbl.new_td_txt(row, 4, txt) txt = exp["reference"]["name"] tbl.new_td_txt(row, 5, txt) row += 1 tbl.render(self.doc) self.doc.add_page_break()
def buildEnviroMixedTables(self, exposures, title): colWidths = [2, 1.5, 1.5, 2, 2] tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl") # write title tbl.new_th(0, 0, title, colspan=5) # write header tbl.new_th(1, 0, "Region, country (city)") tbl.new_th(1, 1, "Mean, agent") tbl.new_th(1, 2, "Range") tbl.new_th(1, 3, "Comments/\nadditional data") tbl.new_th(1, 4, "References") row = 2 for exp in exposures: for res in exp["results"]: runs = [ tbl.new_run(exp["country"], newline=True, b=True), tbl.new_run( f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}', newline=False, ), ] tbl.new_td_run(row, 0, runs) txt = ( f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),' f' {res["agent"]}' ) tbl.new_td_txt(row, 1, txt) txt = res["exposureRangePrint"] tbl.new_td_txt(row, 2, txt) txt = exp["comments"] or "" tbl.new_td_txt(row, 3, txt) txt = exp["reference"]["name"] tbl.new_td_txt(row, 4, txt) row += 1 tbl.render(self.doc) self.doc.add_page_break()
def buildEnviroMixedTables(self, exposures, title): colWidths = [2, 1.5, 1.5, 2, 2] tbl = TableMaker(colWidths, numHeaders=2, tblStyle="ntpTbl") # write title tbl.new_th(0, 0, title, colspan=5) # write header tbl.new_th(1, 0, "Region, country (city)") tbl.new_th(1, 1, "Mean, agent") tbl.new_th(1, 2, "Range") tbl.new_th(1, 3, "Comments/\nadditional data") tbl.new_th(1, 4, "References") row = 2 for exp in exposures: for res in exp["results"]: runs = [ tbl.new_run(exp["country"], newline=True, b=True), tbl.new_run( f'{exp["location"] or "Not-reported"}, {exp["collectionDate"]}', newline=False, ), ] tbl.new_td_run(row, 0, runs) txt = ( f'{res["exposureLevel"]} {res["units"]} ({res["exposureLevelDescription"]}),' f' {res["agent"]}') tbl.new_td_txt(row, 1, txt) txt = res["exposureRangePrint"] tbl.new_td_txt(row, 2, txt) txt = exp["comments"] or "" tbl.new_td_txt(row, 3, txt) txt = exp["reference"]["name"] tbl.new_td_txt(row, 4, txt) row += 1 tbl.render(self.doc) self.doc.add_page_break()
def build_ROB_table(self, study): widths = [2.8, 0.7, 4.0] tbl = TableMaker(widths, numHeaders=2, firstRowCaption=True, tblStyle="ntpTbl") # add caption tbl.new_td_run(0, 0, self.getTableCaptionRuns(study), colspan=3) # add headers cells = ['Risk of Bias', 'Rating', 'Rating rationale'] for i, cell in enumerate(cells): tbl.new_th(1, i, cell) # add body row = 2 for d in study["qualities"]: tbl.new_td_txt(row, 0, d["metric"]["metric"]) tbl.new_td_txt(row, 1, d["score_symbol"], shade=d["score_shade"]) tbl.new_td_txt(row, 2, strip_tags(d["notes"])) row += 1 return tbl.render(self.doc)
def build_ROB_legend(self): widths = [1.5, 1.0, 0.4, 1.0, 0.4, 1.0, 0.4, 0.4, 1.0, 0.4] tbl = TableMaker(widths, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl") cells = [ {"runs": [TableMaker.new_run("Risk of bias key:", b=True, newline=False)]}, {"text": "Definitely Low"}, {"text": "++", "shade": models.StudyQuality.SCORE_SHADES[4]}, {"text": "Probably Low"}, {"text": "+", "shade": models.StudyQuality.SCORE_SHADES[3]}, {"text": "Probably High"}, {"text": "-", "shade": models.StudyQuality.SCORE_SHADES[2]}, {"text": "NR", "shade": models.StudyQuality.SCORE_SHADES[0]}, {"text": "Definitely High"}, {"text": "--", "shade": models.StudyQuality.SCORE_SHADES[1]}, ] for i, cell in enumerate(cells): if "runs" in cell: tbl.new_td_run(0, i, cell["runs"], shade=cell.get("shade")) else: tbl.new_td_txt(0, i, cell["text"], shade=cell.get("shade")) return tbl.render(self.doc)
def build_ROB_legend(self): widths = [1.5, 1.0, 0.4, 1.0, 0.4, 1.0, 0.4, 0.4, 1.0, 0.4] tbl = TableMaker(widths, numHeaders=0, firstRowCaption=False, tblStyle='ntpTbl') cells = [ {'runs': [TableMaker.new_run('Risk of bias key:', b=True, newline=False)]}, {'text': 'Definitely Low'}, {'text': '++', 'shade': RiskOfBiasScore.SCORE_SHADES[4]}, {'text': 'Probably Low'}, {'text': '+', 'shade': RiskOfBiasScore.SCORE_SHADES[3]}, {'text': 'Probably High'}, {'text': '-', 'shade': RiskOfBiasScore.SCORE_SHADES[2]}, {'text': 'NR', 'shade': RiskOfBiasScore.SCORE_SHADES[0]}, {'text': 'Definitely High'}, {'text': '--', 'shade': RiskOfBiasScore.SCORE_SHADES[1]}, ] for i, cell in enumerate(cells): if 'runs' in cell: tbl.new_td_run(0, i, cell['runs'], shade=cell.get('shade')) else: tbl.new_td_txt(0, i, cell['text'], shade=cell.get('shade')) return tbl.render(self.doc)
def _build_study(self, d): rows = 0 tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl") rowspan = 0 for ep in d["results"]: rowspan += 1 if (len(ep["wrd_incidents"]) > 0 or len(ep["wrd_incidence_significance"]) > 0): rowspan += 1 if (len(ep["wrd_multiplicities"]) > 0 or len(ep["wrd_multiplicity_significance"]) > 0): rowspan += 1 if (len(ep["wrd_total_tumours"]) > 0 or len(ep["wrd_total_tumours_significance"]) > 0): rowspan += 1 # Column A runs = [ tbl.new_run(d["studyDesign"], b=True), tbl.new_run(d["species"], b=True, newline=False), tbl.new_run(f', {d["strain"]} {d["sex"]}'), tbl.new_run(d["ageAtStart"]), tbl.new_run(d["duration"]), tbl.new_run(d["reference"]["name"], newline=False), ] tbl.new_td_run(rows, 0, runs, rowspan=rowspan) # Column B txt = dedent(f"""\ {d["dosingRoute"]} {d["agent"]}, {d["purity"]} {d["vehicle"]} {d["wrd_doses"]} {d["dosingRegimen"]} {d["wrd_nStarts"]} {d["wrd_nSurvivings"]}""") tbl.new_td_txt(rows, 1, txt, rowspan=rowspan) # Columns C, D irows = rows for ep in d["results"]: txt = f'{ep["tumourSite"]}: {ep["histology"]}' runs = [tbl.new_run(txt, b=True, newline=False)] tbl.new_td_run(irows, 2, runs, colspan=2) irows += 1 if (len(ep["wrd_incidents"]) > 0 or len(ep["wrd_incidence_significance"]) > 0): tbl.new_td_txt(irows, 2, ep["wrd_incidents"]) tbl.new_td_txt(irows, 3, ep["wrd_incidence_significance"]) irows += 1 if (len(ep["wrd_multiplicities"]) > 0 or len(ep["wrd_multiplicity_significance"]) > 0): tbl.new_td_txt(irows, 2, ep["wrd_multiplicities"]) tbl.new_td_txt(irows, 3, ep["wrd_multiplicity_significance"]) irows += 1 if (len(ep["wrd_total_tumours"]) > 0 or len(ep["wrd_total_tumours_significance"]) > 0): tbl.new_td_txt(irows, 2, ep["wrd_total_tumours"]) tbl.new_td_txt(irows, 3, ep["wrd_total_tumours_significance"]) irows += 1 # Column E runs = [ tbl.new_run("Principal strengths:", b=True), tbl.new_run(d["wrd_strengths"]), tbl.new_run("Principal limitations:", b=True), tbl.new_run(d["wrd_limitations"]), tbl.new_run("Other comments:", b=True), tbl.new_run(d["wrd_comments"], newline=False), ] tbl.new_td_run(rows, 4, runs, rowspan=rowspan) return tbl
def _build_study(self, study): row = 0 tbl = TableMaker( self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl" ) sites = self.group_results_by_site(study["results"]) study_rowspan = self.get_study_rowspan(sites) # Column A runs = [ tbl.new_run(study["reference"]["name"], b=True), tbl.new_run("Animal:", b=True), tbl.new_run(f'{study["species"]} {study["strain"]}'), tbl.new_run(study["sex"]), tbl.new_run("Animal age at the beginning of exposure:", b=True), tbl.new_run(study["ageAtStart"]), tbl.new_run("Study duration:", b=True), tbl.new_run(study["duration"], newline=False), ] tbl.new_td_run(row, 0, runs, rowspan=study_rowspan) # Column B runs = [ tbl.new_run("Agent and purity:", b=True), tbl.new_run(study["agent"]), tbl.new_run(study["purity"]), tbl.new_run("Exposure route:", b=True), tbl.new_run(study["dosingRoute"]), tbl.new_run("Exposure concentrations, frequency, and duration:", b=True), tbl.new_run(study["dosingRegimen"], newline=False), ] tbl.new_td_run(row, 1, runs, rowspan=study_rowspan) site_row = row for results in list(sites.values()): # Column C & D for result in results: # save significance footnotes notes = result.get("significanceNotes", "") or "" if notes and hash(notes) not in self.footnotes: self.footnotes[hash(notes)] = notes # write histology (and footnote adjustment) txt = result["tumourSite"] histology = result.get("histology") if histology: txt = f"{txt} – {histology}" if result["adjustedIncidence"]: txt += "ᵃ" fn = "ᵃ Adjusted percent incidence based on Poly-3 estimated neoplasm incidence after adjustment for intercurrent mortality." # noqa self.footnotes[hash(fn)] = fn runs = [tbl.new_run(txt, b=True, newline=False)] tbl.new_td_run(site_row, 2, runs, colspan=2) site_row += 1 # write groups for group in result["endpointGroups"]: dose = group["dose"] tbl.new_td_txt(site_row, 2, dose) txt = group.get("incidence", "") val = group.get("incidenceSymbol", None) if val: txt += val val = group.get("incidencePercent", "None") if val: txt += f" ({val}%)" tbl.new_td_txt(site_row, 3, txt) site_row += 1 # write trend test txt = result.get("trendTest") if txt: # italicize 'P' in 'P-value' runs = [ tbl.new_run("Trend ", newline=False), tbl.new_run("P", i=True, newline=False), tbl.new_run(f"-value: {txt}"), ] tbl.new_td_run(site_row, 2, runs, colspan=2) site_row += 1 # Column E first_result = study["results"][0] if len(study["results"]) > 0 else {} # blank runs are extra newlines as requested by report writers runs = [ tbl.new_run("Survival: ", b=True, newline=False), tbl.new_run(first_result["survivalNotes"] or ""), tbl.new_run(""), tbl.new_run("Body weight: ", b=True, newline=False), tbl.new_run(first_result["bodyWeightNotes"] or ""), tbl.new_run(""), tbl.new_run( "Significantly increased preneoplastic lesions: ", b=True, newline=False ), tbl.new_run(first_result["nonNeoplasticFindings"] or ""), tbl.new_run(""), tbl.new_run("Other comments: ", b=True, newline=False), tbl.new_run(first_result["comments"] or ""), tbl.new_run(""), tbl.new_run( f'Overall utility: [{study["overallUtility"]}] ', b=True, newline=False ), tbl.new_run(study["overallUtilityRationale"] or ""), ] tbl.new_td_run(row, 4, runs, rowspan=study_rowspan) return tbl
def _build_study(self, study): row = 0 tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl") sites = self.group_results_by_site(study["results"]) study_rowspan = self.get_study_rowspan(sites) # Column A runs = [ tbl.new_run(study["reference"]["name"], b=True), tbl.new_run("Animal:", b=True), tbl.new_run(f'{study["species"]} {study["strain"]}'), tbl.new_run(study["sex"]), tbl.new_run("Animal age at the beginning of exposure:", b=True), tbl.new_run(study["ageAtStart"]), tbl.new_run("Study duration:", b=True), tbl.new_run(study["duration"], newline=False), ] tbl.new_td_run(row, 0, runs, rowspan=study_rowspan) # Column B runs = [ tbl.new_run("Agent and purity:", b=True), tbl.new_run(study["agent"]), tbl.new_run(study["purity"]), tbl.new_run("Exposure route:", b=True), tbl.new_run(study["dosingRoute"]), tbl.new_run("Exposure concentrations, frequency, and duration:", b=True), tbl.new_run(study["dosingRegimen"], newline=False), ] tbl.new_td_run(row, 1, runs, rowspan=study_rowspan) site_row = row for results in list(sites.values()): # Column C & D for result in results: # save significance footnotes notes = result.get("significanceNotes", "") or "" if notes and hash(notes) not in self.footnotes: self.footnotes[hash(notes)] = notes # write histology (and footnote adjustment) txt = result["tumourSite"] histology = result.get("histology") if histology: txt = f"{txt} – {histology}" if result["adjustedIncidence"]: txt += "ᵃ" fn = "ᵃ Adjusted percent incidence based on Poly-3 estimated neoplasm incidence after adjustment for intercurrent mortality." # noqa self.footnotes[hash(fn)] = fn runs = [tbl.new_run(txt, b=True, newline=False)] tbl.new_td_run(site_row, 2, runs, colspan=2) site_row += 1 # write groups for group in result["endpointGroups"]: dose = group["dose"] tbl.new_td_txt(site_row, 2, dose) txt = group.get("incidence", "") val = group.get("incidenceSymbol", None) if val: txt += val val = group.get("incidencePercent", "None") if val: txt += f" ({val}%)" tbl.new_td_txt(site_row, 3, txt) site_row += 1 # write trend test txt = result.get("trendTest") if txt: # italicize 'P' in 'P-value' runs = [ tbl.new_run("Trend ", newline=False), tbl.new_run("P", i=True, newline=False), tbl.new_run(f"-value: {txt}"), ] tbl.new_td_run(site_row, 2, runs, colspan=2) site_row += 1 # Column E first_result = study["results"][0] if len(study["results"]) > 0 else {} # blank runs are extra newlines as requested by report writers runs = [ tbl.new_run("Survival: ", b=True, newline=False), tbl.new_run(first_result["survivalNotes"] or ""), tbl.new_run(""), tbl.new_run("Body weight: ", b=True, newline=False), tbl.new_run(first_result["bodyWeightNotes"] or ""), tbl.new_run(""), tbl.new_run("Significantly increased preneoplastic lesions: ", b=True, newline=False), tbl.new_run(first_result["nonNeoplasticFindings"] or ""), tbl.new_run(""), tbl.new_run("Other comments: ", b=True, newline=False), tbl.new_run(first_result["comments"] or ""), tbl.new_run(""), tbl.new_run(f'Overall utility: [{study["overallUtility"]}] ', b=True, newline=False), tbl.new_run(study["overallUtilityRationale"] or ""), ] tbl.new_td_run(row, 4, runs, rowspan=study_rowspan) return tbl
def _build_description(self, desc, site): results = desc["organSiteResults"][site] row = 0 tbl = TableMaker(self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl") rowspan = self.get_desc_rowspan(results) # Column A runs = [ tbl.new_run(desc["reference"]["name"]), tbl.new_run(desc["studyDesign"]), tbl.new_run(to_string(desc, "location")), tbl.new_run("Enrollment or follow-up:", b=True), tbl.new_run(to_string(desc, "enrollmentDates")), ] tbl.new_td_run(row, 0, runs, rowspan=rowspan) # Column B if desc["isCaseControl"]: txt = (f'Cases: {desc.get("populationSizeCases", "")};' f' Controls: {desc.get("populationSizeControls", "")}') descriptors = desc.get("otherPopulationDescriptors") if descriptors is not None: txt = dedent(f"""\ {descriptors} {txt}""") popD = tbl.new_run(txt) else: popD = tbl.new_run( dedent(f"""\ {desc.get("otherPopulationDescriptors", "")} {desc.get("cohortPopulationSize", "")}""")) runs = [ tbl.new_run("Population:", b=True), popD, tbl.new_run("Exposure assessment method: ", b=True, newline=False), tbl.new_run(desc["exposureAssessmentType"], newline=False), ] tbl.new_td_run(row, 1, runs, rowspan=rowspan) result_row = row for res in results: # Columns C,D result_rowspan = self.get_result_rowspan(res) risk_row = result_row if res.get("organSite") or res.get("effectMeasure"): txt = str(res["organSite"]) if res.get("organSite") else "" if res.get("effectMeasure"): txt += ": " if len(txt) > 0 else "" txt += res["effectMeasure"] if res.get("effectUnits") is not None: txt += f' {res["effectUnits"]}' run = [tbl.new_run(txt, b=True, newline=False)] tbl.new_td_run(risk_row, 2, run, colspan=2) risk_row += 1 for est in res["riskEstimates"]: tbl.new_td_txt(risk_row, 2, est["exposureCategory"]) tbl.new_td_txt(risk_row, 3, est["riskFormatted"]) risk_row += 1 if res.get("trendTest"): run = [ tbl.new_run("Trend-test ", newline=False), tbl.new_run("p", i=True, newline=False), tbl.new_run("-value: ", newline=False), tbl.new_run(res["trendTest"], newline=False), ] tbl.new_td_run(risk_row, 2, run, colspan=2) risk_row += 1 # Column E tbl.new_td_txt(result_row, 4, res["wrd_covariatesList"], rowspan=result_rowspan) # update result_row result_row = result_row + result_rowspan # Column F runs = [] wrd_notes = desc.get("wrd_notes") if wrd_notes is not None and wrd_notes != "": runs.append(tbl.new_run(wrd_notes)) additional_results = "\n".join([ res["additionalResults"] for res in results if ("additionalResults" in res and res["additionalResults"] is not None and res["additionalResults"] is not "") ]) if additional_results is "": additional_results = "-" runs.extend([ tbl.new_run("Exposure information:", b=True), tbl.new_run(to_string(desc, "exposureLevel")), tbl.new_run("Strengths:", b=True), tbl.new_run(to_string(desc, "strengths")), tbl.new_run("Limitations:", b=True), tbl.new_run(to_string(desc, "limitations")), tbl.new_run("Additional results:", b=True), tbl.new_run(additional_results), tbl.new_run("Confidence in evidence:", b=True), tbl.new_run(to_string(desc, "confidenceInEvidence"), newline=False), ]) tbl.new_td_run(row, 5, runs, rowspan=rowspan) return tbl
def _build_description(self, desc, site): results = desc["organSiteResults"][site] row = 0 tbl = TableMaker( self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl" ) rowspan = self.get_desc_rowspan(results) # Column A runs = [ tbl.new_run(desc["reference"]["name"]), tbl.new_run(desc["studyDesign"]), tbl.new_run(to_string(desc, "location")), tbl.new_run("Enrollment or follow-up:", b=True), tbl.new_run(to_string(desc, "enrollmentDates")), ] tbl.new_td_run(row, 0, runs, rowspan=rowspan) # Column B if desc["isCaseControl"]: txt = ( f'Cases: {desc.get("populationSizeCases", "")};' f' Controls: {desc.get("populationSizeControls", "")}' ) descriptors = desc.get("otherPopulationDescriptors") if descriptors is not None: txt = dedent( f"""\ {descriptors} {txt}""" ) popD = tbl.new_run(txt) else: popD = tbl.new_run( dedent( f"""\ {desc.get("otherPopulationDescriptors", "")} {desc.get("cohortPopulationSize", "")}""" ) ) runs = [ tbl.new_run("Population:", b=True), popD, tbl.new_run("Exposure assessment method: ", b=True, newline=False), tbl.new_run(desc["exposureAssessmentType"], newline=False), ] tbl.new_td_run(row, 1, runs, rowspan=rowspan) result_row = row for res in results: # Columns C,D result_rowspan = self.get_result_rowspan(res) risk_row = result_row if res.get("organSite") or res.get("effectMeasure"): txt = str(res["organSite"]) if res.get("organSite") else "" if res.get("effectMeasure"): txt += ": " if len(txt) > 0 else "" txt += res["effectMeasure"] if res.get("effectUnits") is not None: txt += f' {res["effectUnits"]}' run = [tbl.new_run(txt, b=True, newline=False)] tbl.new_td_run(risk_row, 2, run, colspan=2) risk_row += 1 for est in res["riskEstimates"]: tbl.new_td_txt(risk_row, 2, est["exposureCategory"]) tbl.new_td_txt(risk_row, 3, est["riskFormatted"]) risk_row += 1 if res.get("trendTest"): run = [ tbl.new_run("Trend-test ", newline=False), tbl.new_run("p", i=True, newline=False), tbl.new_run("-value: ", newline=False), tbl.new_run(res["trendTest"], newline=False), ] tbl.new_td_run(risk_row, 2, run, colspan=2) risk_row += 1 # Column E tbl.new_td_txt( result_row, 4, res["wrd_covariatesList"], rowspan=result_rowspan ) # update result_row result_row = result_row + result_rowspan # Column F runs = [] wrd_notes = desc.get("wrd_notes") if wrd_notes is not None and wrd_notes != "": runs.append(tbl.new_run(wrd_notes)) additional_results = "\n".join( [ res["additionalResults"] for res in results if ( "additionalResults" in res and res["additionalResults"] is not None and res["additionalResults"] is not "" ) ] ) if additional_results is "": additional_results = "-" runs.extend( [ tbl.new_run("Exposure information:", b=True), tbl.new_run(to_string(desc, "exposureLevel")), tbl.new_run("Strengths:", b=True), tbl.new_run(to_string(desc, "strengths")), tbl.new_run("Limitations:", b=True), tbl.new_run(to_string(desc, "limitations")), tbl.new_run("Additional results:", b=True), tbl.new_run(additional_results), tbl.new_run("Confidence in evidence:", b=True), tbl.new_run(to_string(desc, "confidenceInEvidence"), newline=False), ] ) tbl.new_td_run(row, 5, runs, rowspan=rowspan) return tbl
def _build_result(self, res): rows = 0 tbl = TableMaker( self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl" ) rowspan = len(res["riskEstimates"]) # Column A txt = dedent( f"""\ {res["descriptive"]["reference"]["name"]} {res["descriptive"]["studyDesign"]} {res["descriptive"]["location"]} {res["descriptive"]["enrollmentDates"]}""" ) tbl.new_td_txt(rows, 0, txt, rowspan=rowspan) # Column B if res["descriptive"]["isCaseControl"]: popD = tbl.new_run( dedent( f"""\ {res["descriptive"].get("eligibilityCriteria", "")} Cases: {res["descriptive"].get("populationSizeCase", "")} Controls: {res["descriptive"].get("populationSizeControl", "")}""" ) ) else: popD = tbl.new_run( dedent( f"""\ {res["descriptive"].get("eligibilityCriteria", "")} {res["descriptive"].get("populationSize", "")}""" ) ) runs = [ popD, tbl.new_run("Exposure assessment method: ", b=True, newline=False), tbl.new_run(res["descriptive"]["exposureAssessmentType"], newline=False), ] if res.get("organSite"): runs.insert(0, tbl.new_run(res["organSite"], b=True)) tbl.new_td_run(rows, 1, runs, rowspan=rowspan) # Columns C,D,E for i, est in enumerate(res["riskEstimates"]): tbl.new_td_txt(rows + i, 2, est["exposureCategory"]) tbl.new_td_txt(rows + i, 3, est["numberExposed"]) tbl.new_td_txt(rows + i, 4, est["riskFormatted"]) # Column F txt = res["wrd_covariatesList"] runs = [tbl.new_run(res["wrd_covariatesList"])] if res["hasTrendTest"]: runs.extend( [ tbl.new_run("Trend-test ", newline=False), tbl.new_run("P", i=True, newline=False), tbl.new_run(f'-value: {res["trendTest"]}', newline=False), ] ) tbl.new_td_run(rows, 5, runs, rowspan=rowspan) # Column G runs = [ tbl.new_run(res["descriptive"]["wrd_notes"]), tbl.new_run("Strengths:", b=True), tbl.new_run(res["descriptive"]["strengths"]), tbl.new_run("Limitations:", b=True), tbl.new_run(res["descriptive"]["limitations"], newline=False), ] tbl.new_td_run(rows, 6, runs, rowspan=rowspan) return tbl
def _build_description(self, d): rows = 0 tbl = TableMaker( self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl" ) for res in d["results"]: res["_rowspan"] = max(len(res["riskEstimates"]), 1) effectUnits = res.get("effectUnits", None) if effectUnits and len(effectUnits) > 0: res["_rowspan"] += 1 if res["hasTrendTest"]: res["_rowspan"] += 1 st_rowspan = sum(res["_rowspan"] for res in d["results"]) # Column A runs = [ tbl.new_run(d["reference"]["name"]), tbl.new_run(d["location"]), tbl.new_run(d["enrollmentDates"]), tbl.new_run(d["studyDesign"]), ] tbl.new_td_run(rows, 0, runs, rowspan=st_rowspan) # Column B runs = self.getCol2(d, tbl) tbl.new_td_run(rows, 1, runs, rowspan=st_rowspan) # Columns C, D, E, F, G irows = rows for res in d["results"]: additionalRows = 0 tbl.new_td_txt(irows, 2, res["printOrganSite"], rowspan=res["_rowspan"]) tbl.new_td_txt(irows, 6, res["wrd_covariatesList"], rowspan=res["_rowspan"]) effectUnits = res.get("effectUnits", None) if effectUnits and len(effectUnits) > 0: tbl.new_td_txt(irows, 3, effectUnits, colspan=3) additionalRows += 1 stratum = res.get("stratum", None) for i, est in enumerate(res["riskEstimates"]): runs = [] if i == 0 and stratum and len(stratum) > 0: runs.append(tbl.new_run(f"{stratum}: ", b=True, newline=False)) runs.append(tbl.new_run(est["exposureCategory"], newline=False)) tbl.new_td_run(irows + additionalRows, 3, runs) tbl.new_td_txt(irows + additionalRows, 4, est["numberExposed"]) tbl.new_td_txt(irows + additionalRows, 5, est["riskFormatted"]) additionalRows += 1 if res["hasTrendTest"]: txt = f'Trend-test p-value: {res["trendTest"]}' tbl.new_td_txt(irows + additionalRows, 3, txt, colspan=3) additionalRows += 1 irows += additionalRows # Column H runs = [ tbl.new_run(d["wrd_notes"]), tbl.new_run("Strengths: ", b=True, newline=False), tbl.new_run(d.get("strengths", "")), tbl.new_run("Limitations: ", b=True, newline=False), tbl.new_run(d.get("limitations", "")), ] tbl.new_td_run(rows, 7, runs, rowspan=st_rowspan) return tbl
def _build_study(self, d): rows = 0 tbl = TableMaker( self.COLUMN_WIDTHS, numHeaders=0, firstRowCaption=False, tblStyle="ntpTbl" ) rowspan = 0 for ep in d["results"]: rowspan += 1 if ( len(ep["wrd_incidents"]) > 0 or len(ep["wrd_incidence_significance"]) > 0 ): rowspan += 1 if ( len(ep["wrd_multiplicities"]) > 0 or len(ep["wrd_multiplicity_significance"]) > 0 ): rowspan += 1 if ( len(ep["wrd_total_tumours"]) > 0 or len(ep["wrd_total_tumours_significance"]) > 0 ): rowspan += 1 # Column A runs = [ tbl.new_run(d["studyDesign"], b=True), tbl.new_run(d["species"], b=True, newline=False), tbl.new_run(f', {d["strain"]} {d["sex"]}'), tbl.new_run(d["ageAtStart"]), tbl.new_run(d["duration"]), tbl.new_run(d["reference"]["name"], newline=False), ] tbl.new_td_run(rows, 0, runs, rowspan=rowspan) # Column B txt = dedent( f"""\ {d["dosingRoute"]} {d["agent"]}, {d["purity"]} {d["vehicle"]} {d["wrd_doses"]} {d["dosingRegimen"]} {d["wrd_nStarts"]} {d["wrd_nSurvivings"]}""" ) tbl.new_td_txt(rows, 1, txt, rowspan=rowspan) # Columns C, D irows = rows for ep in d["results"]: txt = f'{ep["tumourSite"]}: {ep["histology"]}' runs = [tbl.new_run(txt, b=True, newline=False)] tbl.new_td_run(irows, 2, runs, colspan=2) irows += 1 if ( len(ep["wrd_incidents"]) > 0 or len(ep["wrd_incidence_significance"]) > 0 ): tbl.new_td_txt(irows, 2, ep["wrd_incidents"]) tbl.new_td_txt(irows, 3, ep["wrd_incidence_significance"]) irows += 1 if ( len(ep["wrd_multiplicities"]) > 0 or len(ep["wrd_multiplicity_significance"]) > 0 ): tbl.new_td_txt(irows, 2, ep["wrd_multiplicities"]) tbl.new_td_txt(irows, 3, ep["wrd_multiplicity_significance"]) irows += 1 if ( len(ep["wrd_total_tumours"]) > 0 or len(ep["wrd_total_tumours_significance"]) > 0 ): tbl.new_td_txt(irows, 2, ep["wrd_total_tumours"]) tbl.new_td_txt(irows, 3, ep["wrd_total_tumours_significance"]) irows += 1 # Column E runs = [ tbl.new_run("Principal strengths:", b=True), tbl.new_run(d["wrd_strengths"]), tbl.new_run("Principal limitations:", b=True), tbl.new_run(d["wrd_limitations"]), tbl.new_run("Other comments:", b=True), tbl.new_run(d["wrd_comments"], newline=False), ] tbl.new_td_run(rows, 4, runs, rowspan=rowspan) return tbl
def build_summary_table(self, ag): widths = [2.5, 2.7, 1.5, 0.5, 1.2, 1.6] tbl = TableMaker(widths, numHeaders=3, firstRowCaption=True, tblStyle="ntpTbl") doses = self.getDoses(ag) firstDose = doses.keys()[0] # add caption tbl.new_td_txt(0, 0, ag['name'], colspan=6) # add headers tbl.new_th(1, 0, r'Reference, Animal Model, and Dosing', rowspan=2) tbl.new_th(1, 1, r'Health outcome', rowspan=2) tbl.new_th(1, 2, r'Results', colspan=4) tbl.new_th(2, 2, u'Dose ({0})'.format(firstDose)) tbl.new_th(2, 3, r'N') tbl.new_th(2, 4, u'Mean \u00B1 SD',) tbl.new_th(2, 5, r'% control (95% CI)') # build endpoint rows rows = 3 for ep in ag["eps"]: if ep["data_extracted"] == False: continue # add endpoint-name as first-row tbl.new_td_run( rows, 2, [TableMaker.new_run(ep["name"], i=True, newline=False)], colspan=4 ) rows += 1 # build column-header table data_type = ep["data_type"] for i, eg in enumerate(ep["groups"]): ci = [] resp = u"-" if data_type == "C": resp = unicode(eg.get("response", "-")) if eg.get('stdev') is not None: resp += u' \u00B1 {0:.2f}'.format(eg["stdev"]) elif data_type in ["D", "DC"]: if eg.get("incidence") is not None: resp = u'{0}/{1}'.format(eg["incidence"], eg["n"]) ci.append(u"NR") else: # ["P"] resp = u'NR' if i != 0 and eg.get("percentControlMean") is not None: ci.append("{0:.1f}".format(eg["percentControlMean"])) if eg.get("percentControlLow") is not None and eg.get("percentControlHigh") is not None: ci.append(u'({0:.1f}, {1:.1f})'.format(eg["percentControlLow"], eg["percentControlHigh"])) ci = u" ".join(ci) tbl.new_td_txt(rows, 2, unicode(doses[firstDose][i])) tbl.new_td_txt(rows, 3, unicode(eg.get("n", "-"))) tbl.new_td_txt(rows, 4, resp) tbl.new_td_txt(rows, 5, ci) rows += 1 else: # add blank cells if none-exist tbl.new_td_txt(3, 2, "") tbl.new_td_txt(3, 3, "") tbl.new_td_txt(3, 4, "") tbl.new_td_txt(3, 5, "") # adjust rowspans for summary rows rowspan = rows - 3 tbl.new_td_run(3, 0, self.getStudyDetailsRuns(ag, doses), rowspan=rowspan) tbl.new_td_run(3, 1, self.getHealthOutcomes(ag), rowspan=rowspan) tbl.render(self.doc) self.doc.add_paragraph("\n")