14.2.83. camcops_server.cc_modules.cc_patient

camcops_server/cc_modules/cc_patient.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/>.


Patients.

class camcops_server.cc_modules.cc_patient.DistinctPatientReport[source]

Report to show distinct patients.

get_query(req: CamcopsRequest) → sqlalchemy.sql.selectable.SelectBase[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.

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

Descriptive title for display purposes.

class camcops_server.cc_modules.cc_patient.Patient(**kwargs)[source]

Class representing a patient.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

add_extra_idnum_info_to_row(row: Dict[str, Any]) → None[source]

For the DB_PATIENT_ID_PER_ROW export option. Adds additional ID number info to a row.

Parameters:row – future database row, as a dictionary
apply_special_note(req: CamcopsRequest, note: str, audit_msg: str = 'Special note applied manually') → None[source]

Manually applies a special note to a patient. WRITES TO DATABASE.

audit(req: CamcopsRequest, details: str, from_console: bool = False) → None[source]

Audits an action to this patient.

delete_with_dependants(req: CamcopsRequest) → None[source]

Delete the patient with all its dependent objects.

gen_patient_idnums_even_noncurrent() → Generator[[camcops_server.cc_modules.cc_patientidnum.PatientIdNum, NoneType], NoneType][source]

Generates all PatientIdNum objects, including non-current ones.

get_address() → Union[str, NoneType][source]

Returns address (NOT necessarily web-safe).

get_age(req: CamcopsRequest, default: str = '') → Union[int, str][source]

Age (in whole years) today, or default.

get_age_at(when: Union[NoneType, datetime.date, str, arrow.arrow.Arrow], default: str = '') → Union[int, str][source]

Age (in whole years) at a particular date, or default.

get_bare_ptinfo() → camcops_server.cc_modules.cc_simpleobjects.BarePatientInfo[source]

Get basic identifying information, as a camcops_server.cc_modules.cc_simpleobjects.BarePatientInfo object.

get_dob() → Union[pendulum.date.Date, NoneType][source]

Date of birth, as a a timezone-naive date.

get_dob_html(req: CamcopsRequest, longform: bool) → str[source]

HTML fragment for date of birth.

get_dob_str() → Union[str, NoneType][source]

Date of birth, as a string.

get_forename() → str[source]

Get forename (in upper case) or “”.

get_hl7_pid_segment(req: CamcopsRequest, recipient: ExportRecipient) → hl7.containers.Segment[source]

Get HL7 patient identifier (PID) segment.

Parameters:
Returns:

a hl7.Segment object

get_iddesc(req: CamcopsRequest, which_idnum: int) → Union[str, NoneType][source]

Get value of a specific ID description, if present.

get_idnum_object(which_idnum: int) → Union[camcops_server.cc_modules.cc_patientidnum.PatientIdNum, NoneType][source]

Gets the PatientIdNum object for a specified which_idnum, or None.

get_idnum_objects() → List[camcops_server.cc_modules.cc_patientidnum.PatientIdNum][source]

Returns all PatientIdNum objects for the patient.

These are SQLAlchemy ORM objects.

get_idnum_raw_values_only() → List[int][source]

Get all plain ID number values (ignoring which ID number type they represent) for the patient.

get_idnum_references() → List[camcops_server.cc_modules.cc_simpleobjects.IdNumReference][source]

Returns all camcops_server.cc_modules.cc_simpleobjects.IdNumReference objects for the patient.

These are simple which_idnum/idnum_value pairs.

get_idnum_value(which_idnum: int) → Union[int, NoneType][source]

Get value of a specific ID number, if present.

get_idshortdesc(req: CamcopsRequest, which_idnum: int) → Union[str, NoneType][source]

Get value of a specific ID short description, if present.

classmethod get_patient_by_id_device_era(dbsession: sqlalchemy.orm.session.Session, client_id: int, device_id: int, era: str) → Union[_ForwardRef('Patient'), NoneType][source]

Fetch a patient by the client ID, device ID, and era.

classmethod get_patient_by_pk(dbsession: sqlalchemy.orm.session.Session, server_pk: int) → Union[_ForwardRef('Patient'), NoneType][source]

Fetch a patient by the server PK.

classmethod get_patients_by_idnum(dbsession: sqlalchemy.orm.session.Session, which_idnum: int, idnum_value: int, group_id: int = None, current_only: bool = True) → List[_ForwardRef('Patient')][source]

Get all patients matching the specified ID number.

Parameters:
  • dbsession – a sqlalchemy.orm.session.Session
  • which_idnum – which ID number type?
  • idnum_value – actual value of the ID number
  • group_id – optional group ID to restrict to
  • current_only – restrict to _current patients?
Returns:

list of all matching patients

get_sex() → str[source]

Return sex or “”.

get_sex_verbose(default: str = 'sex unknown') → str[source]

Returns HTML-safe version of sex, or default.

get_surname() → str[source]

Get surname (in upper case) or “”.

get_surname_forename_upper() → str[source]

Get “SURNAME, FORENAME” in HTML-safe format, using “(UNKNOWN)” for missing details.

get_tsv_page(req: CamcopsRequest) → camcops_server.cc_modules.cc_tsv.TsvPage[source]

Get a camcops_server.cc_modules.cc_tsv.TsvPage for the patient.

get_xml_root(req: CamcopsRequest, options: camcops_server.cc_modules.cc_simpleobjects.TaskExportOptions = None) → camcops_server.cc_modules.cc_xml.XmlElement[source]

Get root of XML tree, as an camcops_server.cc_modules.cc_xml.XmlElement.

Parameters:
group

Returns the camcops_server.cc_modules.cc_group.Group to which this patient’s record belongs.

has_idnum_type(which_idnum: int) → bool[source]

Does the patient have an ID number of the specified type?

is_editable

Is the patient finalized (no longer available to be edited on the client device), and therefore editable on the server?

is_female() → bool[source]

Is sex ‘F’?

is_male() → bool[source]

Is sex ‘M’?

is_preserved() → bool[source]

Is the patient record preserved and erased from the tablet?

prettystr(req: CamcopsRequest) → str[source]

A prettified string version.

Parameters:req – a camcops_server.cc_modules.cc_request.CamcopsRequest
satisfies_finalize_id_policy() → bool[source]

Does the patient satisfy the finalizing ID policy?

satisfies_id_policy(policy: TokenizedPolicy) → bool[source]

Does the patient satisfy a particular ID policy?

satisfies_upload_id_policy() → bool[source]

Does the patient satisfy the uploading ID policy?

set_idnum_value(req: CamcopsRequest, which_idnum: int, idnum_value: int) → None[source]

Sets an ID number value.

user_may_edit(req: CamcopsRequest) → bool[source]

Does the current user have permission to edit this patient?

class camcops_server.cc_modules.cc_patient.PatientTests(*args, echo: bool = False, database_on_disk: bool = True, **kwargs)[source]

Unit tests.

Parameters:
  • echo – Turn on SQL echo?
  • database_on_disk – Use on-disk (rather than in-memory) SQLite database? Allows dumping of contents.
camcops_server.cc_modules.cc_patient.is_candidate_patient_valid(ptinfo: camcops_server.cc_modules.cc_simpleobjects.BarePatientInfo, group: Group, finalizing: bool) → Tuple[bool, str][source]

Is the specified patient acceptable to upload into this group?

Checks:

  • group upload or finalize policy

Todo

is_candidate_patient_valid: check against predefined patients, if the group wants

Parameters:
Returns:

valid, reason

Return type:

tuple