19.1.13. camcops_server.cc_modules.cc_db


Copyright (C) 2012-2018 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/>.


class camcops_server.cc_modules.cc_db.GenericTabletRecordMixin[source]

From the server’s perspective, _pk is unique. However, records are defined also in their tablet context, for which an individual tablet (defined by the combination of _device_id and _era) sees its own PK, “id”.

create_fresh(req: CamcopsRequest, device_id: int, era: str, group_id: int) → None[source]

Used to create a record from scratch.

get_lineage() → List[GenericTabletRecordMixin][source]

Returns all records that are part of the same “lineage”, that is: matching on id/device_id/era, but including both current and any historical non-current versions.

get_summaries(req: CamcopsRequest) → List[camcops_server.cc_modules.cc_summaryelement.SummaryElement][source]

Return a list of summary value objects, for this database object (not any dependent classes/tables).

get_summary_names(req: CamcopsRequest) → List[str][source]

Returns a list of summary field names.

manually_erase_with_dependants(req: CamcopsRequest) → None[source]

Manually erases a standard record and marks it so erased. The object remains _current (if it was), as a placeholder, but its contents are wiped. WRITES TO DATABASE.

mark_as_deleted(req: CamcopsRequest) → None[source]

Ends the history chain and marks this record as non-current.

set_predecessor(req: CamcopsRequest, predecessor: GenericTabletRecordMixin) → None[source]

Used for some unusual server-side manipulations (e.g. editing patient details). The “self” object replaces the predecessor, so “self” becomes current and refers back to “predecessor”, while “predecessor” becomes non-current and refers forward to “self”.

camcops_server.cc_modules.cc_db.add_multiple_columns(cls: Type, prefix: str, start: int, end: int, coltype=<class 'sqlalchemy.sql.sqltypes.Integer'>, colkwargs: Dict[str, Any] = None, comment_fmt: str = None, comment_strings: List[str] = None, minimum: Union[int, float] = None, maximum: Union[int, float] = None, pv: List[Any] = None) → None[source]

Add a sequence of SQLAlchemy columns to a class. Called from a metaclass.

Parameters:
  • cls – class to which to add columns
  • prefix – Fieldname will be prefix + str(n), where n defined as below.
  • start – Start of range.
  • end – End of range. Thus: i will range from 0 to (end - start) inclusive; n will range from start to end inclusive.
  • coltype – SQLAlchemy column type, in either of these formats: (a) Integer (of general type Type[TypeEngine]?); (b) Integer() (of general type TypeEngine).
  • colkwargs – SQLAlchemy column arguments, as in Column(name, coltype, **colkwargs)
  • comment_fmt – Format string defining field comments. Substitutable values are: {n}: field number (from range). {s}: comment_strings[i], or “” if out of range.
  • comment_strings – see comment_fmt
  • minimum – minimum permitted value, or None
  • maximum – maximum permitted value, or None
  • pv – list of permitted values, or None
camcops_server.cc_modules.cc_db.ancillary_relationship(parent_class_name: str, ancillary_class_name: str, ancillary_fk_to_parent_attr_name: str, ancillary_order_by_attr_name: str = None, read_only: bool = True) → sqlalchemy.orm.relationships.RelationshipProperty[source]

Implements a one-to-many relationship, i.e. one parent to many ancillaries.