Copyright (C) 2012-2020 Rudolf Cardinal (email@example.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 <https://www.gnu.org/licenses/>.
Functions for handling filenames, and some associated constants.
Types of informatino that can be used to autogenerate a filename.
Parts of the patient information that can be used to autogenerate the “patient” part of a filename specification.
change_filename_ext(filename: str, new_extension_with_dot: str) → str¶
Replaces the extension, i.e. the part of the filename after its last ‘.’.
convert_string_for_filename(s: str, allow_paths: bool = False) → str¶
Remove characters that don’t play nicely in filenames across multiple operating systems.
filename_spec_is_valid(filename_spec: str, valid_which_idnums: List[int]) → bool¶
filename_specappears valid; otherwise
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¶
Get filename, for file exports/transfers. Also used for e-mail headers and bodies.
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
PatientIdNumobjects for the patient
creation_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)
the generated filename
patient_spec_for_filename_is_valid(patient_spec: str, valid_which_idnums: List[int]) → bool¶
patient_specappears valid; otherwise