Beispiel #1
0
 def set_always(self):
     """Set the things we set every time the script is invoked (time!)."""
     self.NOW_LOCAL_TZ = cc_dt.get_now_localtz()
     # ... we want nearly all our times offset-aware
     # ... http://stackoverflow.com/questions/4530069
     self.NOW_UTC_WITH_TZ = cc_dt.convert_datetime_to_utc(self.NOW_LOCAL_TZ)
     self.NOW_UTC_NO_TZ = cc_dt.convert_datetime_to_utc_notz(self.NOW_LOCAL_TZ)
     self.NOW_LOCAL_TZ_ISO8601 = cc_dt.format_datetime(self.NOW_LOCAL_TZ, DATEFORMAT.ISO8601)
     self.TODAY = datetime.date.today()  # fetches the local date
Beispiel #2
0
def get_export_filename(patient_spec_if_anonymous, patient_spec,
                        filename_spec, task_format,
                        is_anonymous=False,
                        surname=None, forename=None, dob=None, sex=None,
                        idnums=[None]*NUMBER_OF_IDNUMS,
                        idshortdescs=[""]*NUMBER_OF_IDNUMS,
                        creation_datetime=None, basetable=None, serverpk=None):
    """Get filename, for file exports/transfers."""
    if idnums is None:
        idnums = [None]*NUMBER_OF_IDNUMS
    if idshortdescs is None:
        idshortdescs = [""]*NUMBER_OF_IDNUMS
    d = dict(
        surname=surname or "",
        forename=forename or "",
        dob=(
            cc_dt.format_datetime(dob, DATEFORMAT.FILENAME_DATE_ONLY, "")
            if dob else ""
        ),
        sex=sex or "",
    )
    all_id_components = []
    for n in range(1, NUMBER_OF_IDNUMS + 1):
        i = n - 1
        nstr = str(n)
        has_num = idnums[i] is not None
        has_desc = bool(idshortdescs[i])
        d["idshortdesc"+nstr] = idshortdescs[i] if has_num and has_desc else ""
        d["idnum"+nstr] = str(idnums[i]) if has_num else ""
        if has_num and has_desc:
            all_id_components.append(idshortdescs[i] + "-" + str(idnums[i]))
    d["allidnums"] = "_".join(all_id_components)
    if is_anonymous:
        patient = patient_spec_if_anonymous
    else:
        patient = unicode(patient_spec).format(**d)
    d.update(dict(
        patient=patient,
        created=cc_dt.format_datetime(creation_datetime,
                                      DATEFORMAT.FILENAME, ""),
        now=cc_dt.format_datetime(cc_dt.get_now_localtz(),
                                  DATEFORMAT.FILENAME),
        tasktype=str(basetable or ""),
        serverpk=str(serverpk or ""),
        filetype=task_format.lower(),
        anonymous=patient_spec_if_anonymous if is_anonymous else "",
    ))
    return convert_string_for_filename(
        unicode(filename_spec).format(**d), allow_paths=True)