15.2.136. camcops_server.cc_modules.cc_patient¶
camcops_server/cc_modules/cc_patient.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/>.
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
Selectstatement to execute the report.(Do not return a
Query; that can no longer be executed viasession.execute()in SQLAlchemy 2.)Parameters are passed in via the request.
- class camcops_server.cc_modules.cc_patient.Patient(**kwargs)[source]¶
Class representing a patient.
- __init__(**kwargs)¶
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_ROWexport 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.
- property duplicates: set['Patient']¶
Returns a set of patients that have an ID Number that matches this one. For a patient to be considered a duplicate, the ID number needs to match on:
Group
Type of ID Number (e.g. NHS Number)
Value of ID number
Device where patient was created
and have the “current” flag set to True
- gen_patient_idnums_even_noncurrent() Generator[camcops_server.cc_modules.cc_patientidnum.PatientIdNum, None, None][source]¶
Generates all
PatientIdNumobjects, including non-current ones.
- get_age(req: CamcopsRequest, default: str = '') Union[int, str][source]¶
Age (in whole years) today, or default.
- get_age_at(when: Union[None, datetime.datetime, datetime.date, pendulum.datetime.DateTime, 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.BarePatientInfoobject.
- get_fhir_bundle_entry(req: CamcopsRequest, recipient: ExportRecipient) Dict[str, Any][source]¶
Returns a dictionary, suitable for serializing to JSON, that encapsulates patient identity information in a FHIR bundle.
- get_fhir_identifier(req: CamcopsRequest, recipient: ExportRecipient) fhirclient.models.identifier.Identifier[source]¶
Returns a FHIR identifier for this patient, as a
fhirclient.models.identifier.Identifierobject.This pairs a URL to our CamCOPS server indicating the ID number type (as the “system”) with the actual ID number (as the “value”).
For debugging situations, it falls back to a default identifier (using the PK on our CamCOPS server).
- get_fhir_subject_ref(req: CamcopsRequest, recipient: ExportRecipient) Dict[source]¶
Returns a FHIRReference (in JSON dict format) used to refer to this patient as a “subject” of some other entry (like a questionnaire).
- get_forename_surname() str[source]¶
Get “Forename Surname” as a string, using “(UNKNOWN)” for missing details.
- get_hl7_pid_segment(req: CamcopsRequest, recipient: ExportRecipient) hl7.containers.Segment[source]¶
Get HL7 patient identifier (PID) segment.
- Parameters
- Returns
a
hl7.Segmentobject
- get_iddesc(req: CamcopsRequest, which_idnum: int) Optional[str][source]¶
Get value of a specific ID description, if present.
- get_idnum_object(which_idnum: int) Optional[camcops_server.cc_modules.cc_patientidnum.PatientIdNum][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
PatientIdNumobjects 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.IdNumReferenceobjects for the patient.These are simple which_idnum/idnum_value pairs.
- get_idnum_value(which_idnum: int) Optional[int][source]¶
Get value of a specific ID number, if present.
- get_idshortdesc(req: CamcopsRequest, which_idnum: int) Optional[str][source]¶
Get value of a specific ID short description, if present.
- get_letter_style_identifiers(req: CamcopsRequest) str[source]¶
Our best guess at the kind of text you’d put in a clinical letter to say “it’s about this patient”.
Example:
Bob Smith (1 Jan 1950, RiO number 123, NHS number 456)
- classmethod get_patient_by_id_device_era(dbsession: sqlalchemy.orm.session.Session, client_id: int, device_id: int, era: str) Optional[camcops_server.cc_modules.cc_patient.Patient][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) Optional[camcops_server.cc_modules.cc_patient.Patient][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: Optional[int] = None, current_only: bool = True) List[camcops_server.cc_modules.cc_patient.Patient][source]¶
Get all patients matching the specified ID number.
- Parameters
dbsession – a
sqlalchemy.orm.session.Sessionwhich_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
_currentpatients?
- Returns
list of all matching patients
- get_sex_verbose(default: str = 'sex unknown') str[source]¶
Returns HTML-safe version of sex, or default.
- get_spreadsheet_page(req: CamcopsRequest) camcops_server.cc_modules.cc_spreadsheet.SpreadsheetPage[source]¶
Get a
camcops_server.cc_modules.cc_spreadsheet.SpreadsheetPagefor the patient.
- get_spreadsheet_schema_elements(req: CamcopsRequest, table_name: str = '') Set[camcops_server.cc_modules.cc_dataclasses.SummarySchemaInfo][source]¶
Follows
get_spreadsheet_page(), but retrieving schema information.
- get_surname_forename_upper() str[source]¶
Get “SURNAME, FORENAME”, using “(UNKNOWN)” for missing details.
- 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
- property group: Optional[Group]¶
Returns the
camcops_server.cc_modules.cc_group.Groupto 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?
- id: sqlalchemy.orm.base.Mapped[int]¶
- prettystr(req: CamcopsRequest) str[source]¶
A prettified string version.
- Parameters
Example:
SMITH, BOB (M, 1 Jan 1950, RiO# 123, NHS# 456)
- satisfies_id_policy(policy: TokenizedPolicy) bool[source]¶
Does the patient satisfy a particular 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?
- when_last_modified: Mapped[Optional[Pendulum]]¶
- camcops_server.cc_modules.cc_patient.is_candidate_patient_valid_for_group(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
ptinfo – a
camcops_server.cc_modules.cc_simpleobjects.BarePatientInforepresenting the patient info to checkgroup – the
camcops_server.cc_modules.cc_group.Groupinto which this patient will be uploaded, if allowedfinalizing – finalizing, rather than uploading?
- Returns
valid, reason
- Return type
tuple
- camcops_server.cc_modules.cc_patient.is_candidate_patient_valid_for_restricted_user(req: CamcopsRequest, ptinfo: camcops_server.cc_modules.cc_simpleobjects.BarePatientInfo) Tuple[bool, str][source]¶
Is the specified patient OK to be uploaded by this user? Performs a check for restricted (single-patient) users; if true, ensures that the identifiers all match the expected patient.
- Parameters
req – the
camcops_server.cc_modules.cc_request.CamcopsRequestptinfo – a
camcops_server.cc_modules.cc_simpleobjects.BarePatientInforepresenting the patient info to check
- Returns
valid, reason
- Return type
tuple