15.2.143. camcops_server.cc_modules.cc_report¶
camcops_server/cc_modules/cc_report.py
Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
CamCOPS reports.
- class camcops_server.cc_modules.cc_report.AverageScoreReport(*args, via_index: bool = True, **kwargs)[source]¶
Used by MAAS, CORE-10 and PBQ to report average scores and progress
- __init__(*args, via_index: bool = True, **kwargs) None [source]¶
- Parameters
via_index – set this to
False
for unit test when you don’t want to have to build a dummy task index.
- get_spreadsheet_pages(req: CamcopsRequest) List[camcops_server.cc_modules.cc_spreadsheet.SpreadsheetPage] [source]¶
We use an SQLAlchemy ORM, rather than Core, method. Why?
“Patient equality” is complex (e.g. same patient_id on same device, or a shared ID number, etc.) – simplicity via Patient.__eq__.
Facilities “is task complete?” checks, and use of Python calculations.
- class camcops_server.cc_modules.cc_report.PercentageSummaryReportMixin[source]¶
Mixin to be used with
Report
.
- class camcops_server.cc_modules.cc_report.PlainReportType(rows: Sequence[Sequence[Any]], column_names: Sequence[str])[source]¶
Simple class to hold the results of a plain report.
- class camcops_server.cc_modules.cc_report.Report[source]¶
Abstract base class representing a report.
If you are writing a report, you must override these attributes:
report_id()
report_title()
One combination of:
(simplest)
get_query()
ORget_rows_colnames()
(for multi-page results)
render_html()
andget_spreadsheet_pages()
(manual control) all
render_*
functions
See the explanations of each.
- static add_task_report_filters(wheres: List[sqlalchemy.sql.elements.ColumnElement]) None [source]¶
Adds any restrictions required to a list of SQLAlchemy Core
WHERE
clauses.Override this (or provide additional filters and call this) to provide global filters to queries used to create reports.
Used by
DateTimeFilteredReportMixin
, etc.The presumption is that the thing being filtered is an instance of
camcops_server.cc_modules.cc_task.Task
.- Parameters
wheres – list of SQL
WHERE
conditions, each represented as an SQLAlchemyColumnElement
. This list is modifed in place. The caller will need to apply the final list to the query.
- classmethod all_subclasses() List[Type[camcops_server.cc_modules.cc_report.Report]] [source]¶
Get all report subclasses, except those not implementing their
report_id
property. Optionally, sort by their title.
- get_form(req: CamcopsRequest) deform.form.Form [source]¶
Returns a Colander form to configure the report. The default usually suffices, and it will use the schema specified in
get_paramform_schema_class()
.
- classmethod get_http_query_keys() List[str] [source]¶
Returns the keys used for the HTTP GET query. They include details of:
which report?
how to view it?
pagination options
report-specific configuration details from
get_specific_http_query_keys()
.
- static get_paramform_schema_class() Type[ReportParamSchema] [source]¶
Returns the class used as the Colander schema for the form that configures the report. By default, this is a simple form that just offers a choice of output format, but you can provide a more extensive one (an example being in
camcops_server.tasks.diagnosis.DiagnosisFinderReportBase
.
- get_query(req: CamcopsRequest) Union[None, sqlalchemy.sql.selectable.SelectBase, sqlalchemy.orm.query.Query] [source]¶
Overriding this function is one way of providing a report. (The other is
get_rows_colnames()
.)To override this function, return the SQLAlchemy Base
Select
statement or the SQLAlchemy ORMQuery
to execute the report.Parameters are passed in via the request.
- get_response(req: CamcopsRequest) pyramid.response.Response [source]¶
Return the report content itself, as an HTTP
Response
.
- get_rows_colnames(req: CamcopsRequest) Optional[camcops_server.cc_modules.cc_report.PlainReportType] [source]¶
Overriding this function is one way of providing a report. (The other is
get_query()
.)To override this function, return a
PlainReportType
with column names and row content.
- classmethod get_specific_http_query_keys() List[str] [source]¶
Additional HTTP GET query keys used by this report. Override to add custom ones.
- static get_test_querydict() Dict[str, Any] [source]¶
What this function returns is used as the specimen Colander
appstruct
for unit tests. The default is an empty dictionary.
- render_single_page_html(req: CamcopsRequest, column_names: Sequence[str], page: camcops_server.cc_modules.cc_pyramid.CamcopsPage) pyramid.response.Response [source]¶
Converts a paginated report into an HTML response.
If you wish, you can override this for more report customization.
- class camcops_server.cc_modules.cc_report.ScoreDetails(name: str, scorefunc: Callable[[Task], Union[None, int, float]], minimum: int, maximum: int, higher_score_is_better: bool = False)[source]¶
Represents a type of score whose progress we want to track over time.
- __init__(name: str, scorefunc: Callable[[Task], Union[None, int, float]], minimum: int, maximum: int, higher_score_is_better: bool = False) None [source]¶
- Parameters
name – human-friendly name of this score
scorefunc – function that can be called with a task instance as its sole parameter and which will return a numerical score (or
None
)minimum – minimum possible value of this score (for display purposes)
maximum – maximum possible value of this score (for display purposes)
higher_score_is_better – is a higher score a better thing?
- camcops_server.cc_modules.cc_report.get_all_report_classes(req: CamcopsRequest) List[Type[Report]] [source]¶
Returns all
Report
(sub)classes, i.e. all report types.
- camcops_server.cc_modules.cc_report.get_report_instance(report_id: str) Optional[camcops_server.cc_modules.cc_report.Report] [source]¶
Creates an instance of a
Report
, given its ID (name), or returnNone
if the ID is invalid.