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.

static no_data_value() Any[source]

The value used for a “no data” cell.

The only reason this is accessible outside this class is for unit testing.

class camcops_server.cc_modules.cc_report.PercentageSummaryReportMixin[source]

Mixin to be used with Report.

get_percentage_summaries(req: CamcopsRequest, column_dict: Dict[str, str], num_answers: int, cell_format: str = '{}', min_answer: int = 0) List[List[str]][source]

Provides a summary of each question, x% of people said each response.

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.

__init__(rows: Sequence[Sequence[Any]], column_names: Sequence[str]) None[source]
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() OR get_rows_colnames()

    • (for multi-page results) render_html() and get_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 SQLAlchemy ColumnElement. 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:

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 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) 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.

classmethod title(req: CamcopsRequest) str[source]

Descriptive title for display purposes.

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?

calculate_improvement(first_score: float, latest_score: float) float[source]

Improvement is positive.

So if higher scores are better, returns latest - first; otherwise returns first - latest.

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 return None if the ID is invalid.