15.2.118. camcops_server.cc_modules.cc_filename¶
camcops_server/cc_modules/cc_filename.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/>.
Functions for handling filenames, and some associated constants.
- class camcops_server.cc_modules.cc_filename.FilenameSpecElement[source]¶
Types of informatino that can be used to autogenerate a filename.
- class camcops_server.cc_modules.cc_filename.PatientSpecElementForFilename[source]¶
Parts of the patient information that can be used to autogenerate the “patient” part of a filename specification.
- camcops_server.cc_modules.cc_filename.change_filename_ext(filename: str, new_extension_with_dot: str) str [source]¶
Replaces the extension, i.e. the part of the filename after its last ‘.’.
- camcops_server.cc_modules.cc_filename.convert_string_for_filename(s: str, allow_paths: bool = False) str [source]¶
Remove characters that don’t play nicely in filenames across multiple operating systems.
- camcops_server.cc_modules.cc_filename.filename_spec_is_valid(filename_spec: str, valid_which_idnums: List[int]) bool [source]¶
Returns
True
if thefilename_spec
appears valid; otherwiseFalse
.
- camcops_server.cc_modules.cc_filename.get_export_filename(req: CamcopsRequest, patient_spec_if_anonymous: str, patient_spec: str, filename_spec: str, filetype: str, is_anonymous: bool = False, surname: str = None, forename: str = None, dob: pendulum.date.Date = None, sex: str = None, idnum_objects: List[PatientIdNum] = None, creation_datetime: pendulum.datetime.DateTime = None, basetable: str = None, serverpk: int = None, skip_conversion_to_safe_filename: bool = False) str [source]¶
Get filename, for file exports/transfers. Also used for e-mail headers and bodies.
- Parameters
patient_spec_if_anonymous – patient specification to be used for anonymous tasks
patient_spec – patient specification to be used for patient-identifiable tasks
filename_spec – specification to use to create the filename (may include patient information from the patient specification)
filetype – task output format and therefore file type (e.g. HTML, PDF, XML)
is_anonymous – is it an anonymous task?
surname – patient’s surname
forename – patient’s forename
dob – patient’s date of birth
sex – patient’s sex
idnum_objects – list of
PatientIdNum
objects for the patientcreation_datetime – date/time the task was created
basetable – name of the task’s base table
serverpk – server PK of the task
skip_conversion_to_safe_filename – don’t bother converting the result to a safe filename (because it’ll be used for something else, like an e-mail subject)
- Returns
the generated filename