14.2.89. camcops_server.cc_modules.cc_report

camcops_server/cc_modules/cc_report.py


Copyright (C) 2012-2019 Rudolf Cardinal (rudolf@pobox.com).

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 <http://www.gnu.org/licenses/>.


CamCOPS reports.

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
  • get_query OR get_rows_colnames

See the explanations of each.

classmethod all_subclasses() → List[Type[_ForwardRef('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:

static get_paramform_schema_class() → Type[_ForwardRef('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[NoneType, 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 ORM Query 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) → Union[camcops_server.cc_modules.cc_report.PlainReportType, NoneType][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_html(req: CamcopsRequest, column_names: List[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.

classmethod title(req: CamcopsRequest) → str[source]

Descriptive title for display purposes.

class camcops_server.cc_modules.cc_report.ReportTests(methodName='runTest')[source]

Unit tests.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

camcops_server.cc_modules.cc_report.get_all_report_classes(req: CamcopsRequest) → List[Type[_ForwardRef('Report')]][source]

Returns all Report (sub)classes, i.e. all report types.

camcops_server.cc_modules.cc_report.get_report_instance(report_id: str) → Union[camcops_server.cc_modules.cc_report.Report, NoneType][source]

Creates an instance of a Report, given its ID (name), or return None if the ID is invalid.