15.2.166. camcops_server.cc_modules.cc_taskschedule

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


class camcops_server.cc_modules.cc_taskschedule.PatientTaskSchedule(**kwargs)[source]

Joining table that associates a patient with a task schedule

__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.

email_body(req: CamcopsRequest) str[source]

Body content (HTML) for an e-mail to the patient – the schedule’s template, populated with patient-specific information.

property email_sent: bool

Has an e-mail been sent to the patient for this schedule?

find_scheduled_task(req: CamcopsRequest, tsi: TaskScheduleItem, start_datetime: pendulum.datetime.DateTime, end_datetime: pendulum.datetime.DateTime) Optional[camcops_server.cc_modules.cc_task.Task][source]

Returns the most recently uploaded task that matches the patient (by any ID number, i.e. via OR), task type and timeframe

get_list_of_scheduled_tasks(req: CamcopsRequest) List[camcops_server.cc_modules.cc_taskschedule.ScheduledTaskInfo][source]

Tasks scheduled for this patient.

class camcops_server.cc_modules.cc_taskschedule.PatientTaskScheduleEmail(**kwargs)[source]

Represents an email send to a patient for a particular task schedule.

__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.

class camcops_server.cc_modules.cc_taskschedule.ScheduledTaskInfo(shortname: str, tablename: str, is_anonymous: bool, task: Optional[camcops_server.cc_modules.cc_task.Task] = None, start_datetime: Optional[pendulum.datetime.DateTime] = None, end_datetime: Optional[pendulum.datetime.DateTime] = None)[source]

Simple representation of a scheduled task (which may also contain the actual completed task, in its task member, if there is one).

__init__(shortname: str, tablename: str, is_anonymous: bool, task: Optional[camcops_server.cc_modules.cc_task.Task] = None, start_datetime: Optional[pendulum.datetime.DateTime] = None, end_datetime: Optional[pendulum.datetime.DateTime] = None) None[source]
property due_now: bool

Are we in the range [start_datetime, end_datetime)?

property due_now_identifiable_and_incomplete: bool

Is this task currently due, identifiable, and incomplete?

property is_complete: bool

Returns whether its associated task is complete..

property is_identifiable_and_incomplete: bool

If this is an anonymous task, returns False. If this is an identifiable task, returns not is_complete.

class camcops_server.cc_modules.cc_taskschedule.TaskSchedule(**kwargs)[source]

A named collection of task schedule items

__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.

user_may_edit(req: CamcopsRequest) bool[source]

May the current user edit this schedule?

class camcops_server.cc_modules.cc_taskschedule.TaskScheduleEmailTemplateFormatter[source]

Safe template formatter for task schedule e-mails.

__init__()[source]
Parameters

allowed_keys – Keys that are permitted within a brace-delimited format string.

class camcops_server.cc_modules.cc_taskschedule.TaskScheduleItem(**kwargs)[source]

An individual item in a task schedule

__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.

description(req: CamcopsRequest) str[source]

Description of this schedule item – which task, due when.

property due_within: Optional[pendulum.duration.Duration]

Returns the “due within” property, e.g. “due within 7 days (of being scheduled to start)”. This is calculated from due_from and due_by.

property task_shortname: str

Short name of the task being scheduled.

camcops_server.cc_modules.cc_taskschedule.task_schedule_item_sort_order() Tuple[Cast, Cast][source]

Returns a tuple of sorting functions for use with SQLAlchemy ORM queries, to sort task schedule items.

The durations are currently stored as seconds e.g. P0Y0MT2594592000.0S and the seconds aren’t zero padded, so we need to do some processing to get them in the order we want.

This will fail if durations ever get stored any other way.

Note that MySQL does not permit “CAST(… AS DOUBLE)” or “CAST(… AS FLOAT)”; you need to use NUMERIC or DECIMAL. However, this raises a warning when running self-tests under SQLite: “SAWarning: Dialect sqlite+pysqlite does not support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage.”