Skip to content
Snippets Groups Projects

Resolve "list of subjects should contain columns dependent on the study"

2 files
+ 41
24
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -22,6 +22,10 @@ DATE_FORMAT_TIME = "%H:%M"
now = datetime.datetime.now()
def date_format_encoding():
return locale.getlocale(locale.LC_TIME)[1] or locale.getpreferredencoding()
@contextmanager
def setlocale(name):
saved = locale.setlocale(locale.LC_TIME)
@@ -31,9 +35,14 @@ def setlocale(name):
locale.setlocale(locale.LC_TIME, saved)
def get_formatted_time(time_format):
return now.strftime(time_format).decode(date_format_encoding())
class MailTemplate(models.Model):
MAILS_TEMPLATE_GENERIC_TAGS = [
("##DATE_FULL##", "Current date when the mail will be generated (long format)", now.strftime(DATE_FORMAT_FULL)),
("##DATE_FULL##", "Current date when the mail will be generated (long format)",
get_formatted_time(DATE_FORMAT_FULL)),
("##DATE_SHORT##", "Current date when the mail will be generated (short format)",
now.strftime(DATE_FORMAT_SHORT)),
("##WORKER##", "The full name of the currently logged in user", "")
@@ -49,7 +58,7 @@ class MailTemplate(models.Model):
("##S_COUNTRY##", "Subject's country of residence", ""),
("##S_SEX##", "Subject's gender", "Male/Female"),
("##S_TYPE##", "Subject's type", "CONTROL/PATIENT"),
("##S_DATE_BORN##", "Subject's date of birth", now.strftime(DATE_FORMAT_SHORT)),
("##S_DATE_BORN##", "Subject's date of birth", get_formatted_time(DATE_FORMAT_SHORT)),
("##S_EMAIL##", "Subject's email address", ""),
("##S_PHONE_NUMBER##", "Subject's phone number", ""),
@@ -63,20 +72,20 @@ class MailTemplate(models.Model):
("##S_DIAGNOSIS_YEAR##", "Subject's year of diagnosis", ""),
("##S_MPOWER_ID##", "Subject's mPower identifier", ""),
("##S_ND_NUMBER##", "Subject's ND number", ""),
("##S_DATE_ADDED##", "Subject's date of creation", now.strftime(DATE_FORMAT_SHORT)),
("##S_DATE_ADDED##", "Subject's date of creation", get_formatted_time(DATE_FORMAT_SHORT)),
]
MAILS_TEMPLATE_VISIT_TAGS = [
("##V_DATE_START_FULL##", "Visit's start date", now.strftime(DATETIME_FORMAT)),
("##V_DATE_START_SHORT##", "Visit's start date", now.strftime(DATE_FORMAT_SHORT)),
("##V_DATE_ENDS_FULL##", "Visit's end date", now.strftime(DATETIME_FORMAT)),
("##V_DATE_ENDS_SHORT##", "Visit's end date", now.strftime(DATE_FORMAT_SHORT)),
("##V_DATE_START_FULL##", "Visit's start date", get_formatted_time(DATETIME_FORMAT)),
("##V_DATE_START_SHORT##", "Visit's start date", get_formatted_time(DATE_FORMAT_SHORT)),
("##V_DATE_ENDS_FULL##", "Visit's end date", get_formatted_time(DATETIME_FORMAT)),
("##V_DATE_ENDS_SHORT##", "Visit's end date", get_formatted_time(DATE_FORMAT_SHORT)),
]
MAILS_TEMPLATE_APPOINTMENT_TAGS = [
("##A_DATE_FULL##", "Appointment's date and time", now.strftime(DATETIME_FORMAT)),
("##A_DATE_SHORT##", "Appointment's date", now.strftime(DATE_FORMAT_SHORT)),
("##A_TIME##", "Appointment's time", now.strftime(DATE_FORMAT_TIME)),
("##A_DATE_FULL##", "Appointment's date and time", get_formatted_time(DATETIME_FORMAT)),
("##A_DATE_SHORT##", "Appointment's date", get_formatted_time(DATE_FORMAT_SHORT)),
("##A_TIME##", "Appointment's time", get_formatted_time(DATE_FORMAT_TIME)),
("##A_FLYING_TEAM##", "Appointment's flying team location", ""),
("##A_LOCATION##", "Appointment's location", "value can be 'Flying Team'"),
("##A_LOCATION_OR_FLYINGTEAM##", "Appointment's real location",
@@ -150,8 +159,8 @@ class MailTemplate(models.Model):
def _add_generic_replacements(self, replacements, worker):
current_datetime = datetime.datetime.now()
replacements.update({
"##DATE_FULL##": current_datetime.strftime(DATE_FORMAT_FULL),
"##DATE_SHORT##": current_datetime.strftime(DATE_FORMAT_SHORT),
"##DATE_FULL##": current_datetime.strftime(DATE_FORMAT_FULL).decode(date_format_encoding()),
"##DATE_SHORT##": current_datetime.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
"##WORKER##": unicode(worker)
})
@@ -164,9 +173,12 @@ class MailTemplate(models.Model):
worker_phone_number = ""
worker_email_address = ""
if appointment.datetime_when is not None:
appointment_date_full = appointment.datetime_when.strftime(DATETIME_FORMAT)
appointment_date_short = appointment.datetime_when.strftime(DATE_FORMAT_SHORT)
appointment_date_time = appointment.datetime_when.strftime(DATE_FORMAT_TIME)
appointment_date_full = appointment.datetime_when.strftime(DATETIME_FORMAT).decode(
date_format_encoding())
appointment_date_short = appointment.datetime_when.strftime(DATE_FORMAT_SHORT).decode(
date_format_encoding())
appointment_date_time = appointment.datetime_when.strftime(DATE_FORMAT_TIME).decode(
date_format_encoding())
else:
appointment_date_full = appointment_date_short = appointment_date_time = ""
replacements.update({
@@ -188,16 +200,17 @@ class MailTemplate(models.Model):
def _add_visit_replacements(self, replacements, visit):
if visit is not None:
replacements.update({
"##V_DATE_START_FULL##": visit.datetime_begin.strftime(DATETIME_FORMAT),
"##V_DATE_START_SHORT##": visit.datetime_begin.strftime(DATE_FORMAT_SHORT),
"##V_DATE_ENDS_FULL##": visit.datetime_end.strftime(DATETIME_FORMAT),
"##V_DATE_ENDS_SHORT##": visit.datetime_end.strftime(DATE_FORMAT_SHORT),
"##V_DATE_START_FULL##": visit.datetime_begin.strftime(DATETIME_FORMAT).decode(date_format_encoding()),
"##V_DATE_START_SHORT##": visit.datetime_begin.strftime(DATE_FORMAT_SHORT).decode(
date_format_encoding()),
"##V_DATE_ENDS_FULL##": visit.datetime_end.strftime(DATETIME_FORMAT).decode(date_format_encoding()),
"##V_DATE_ENDS_SHORT##": visit.datetime_end.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
})
def _add_subject_replacements(self, replacements, study_subject):
if study_subject is not None:
if study_subject.subject.date_born is not None:
date_born = study_subject.subject.date_born.strftime(DATE_FORMAT_SHORT)
date_born = study_subject.subject.date_born.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding())
else:
date_born = None
replacements.update({
@@ -208,7 +221,7 @@ class MailTemplate(models.Model):
"##S_CITY##": study_subject.subject.city,
"##S_COUNTRY##": unicode(study_subject.subject.country),
"##S_DIAGNOSIS_YEAR##": study_subject.year_of_diagnosis,
"##S_DATE_ADDED##": study_subject.date_added.strftime(DATE_FORMAT_SHORT),
"##S_DATE_ADDED##": study_subject.date_added.strftime(DATE_FORMAT_SHORT).decode(date_format_encoding()),
"##S_DATE_BORN##": date_born,
"##S_DIAGNOSIS##": study_subject.diagnosis,
"##S_EMAIL##": study_subject.subject.email,
Loading