def archive_template_url(template_name: str = "", patient_id: str = "", **kwargs) -> str: """ Creates a URL to inspect part of the archive. Args: template_name: short name of the (configurable) template patient_id: patient ID **kwargs: other optional arguments, passed as URL parameters Returns: A URL. """ kwargs = kwargs or {} # type: Dict[str, Any] qparams = kwargs.copy() if template_name: qparams[UrlKeys.TEMPLATE] = template_name filepath = get_archive_template_filepath(template_name) add_file_timestamp_to_url_query(filepath, qparams) if patient_id: qparams[UrlKeys.PATIENT_ID] = patient_id # log.critical("qparams: {!r}", qparams) url = url_with_querystring(reverse(UrlNames.ARCHIVE_TEMPLATE), **qparams) # log.critical(f"archive_template_url: {url!r}") return url
def archive_static_url(filename: str) -> str: """ Returns a URL to download a static file from the archive. Args: filename: filename on disk, within the archive's static directory """ # noqa qparams = {UrlKeys.FILENAME: filename} filepath = get_archive_static_filepath(filename) add_file_timestamp_to_url_query(filepath, qparams) return url_with_querystring(reverse(UrlNames.ARCHIVE_STATIC), **qparams)
def template_html(template_name: str, iframe_class: str = "embedded_attachment", **qparams) -> str: """ HTML element to show aonther archive template inline (not necessarily for a specific patient). Args: template_name: relative filename of the template iframe_class: CSS class for the <iframe> qparams: query parameters to pass to the template """ url = archive_template_url(template_name) final_url = url_with_querystring(url, **qparams) return f'<iframe class="{iframe_class}" src="{final_url}"></iframe>'
def patient_template_html(template_name: str, context: Dict[str, Any], iframe_class: str = "embedded_attachment", **qparams) -> str: """ HTML element to show aonther archive patient template inline. Args: template_name: relative filename of the template context: Mako context iframe_class: CSS class for the <iframe> qparams: query parameters to pass to the template """ get_patient_template_url = context[ ArchiveContextKeys.get_patient_template_url] # noqa url = get_patient_template_url(template_name) final_url = url_with_querystring(url, **qparams) return f'<iframe class="{iframe_class}" src="{final_url}"></iframe>'
def archive_attachment_url( filename: str, patient_id: str = "", content_type: str = "", offered_filename: str = "", guess_content_type: bool = None) -> str: """ Returns a URL to download an archive attachment (e.g. a PDF). Args: filename: filename on disk, within the archive's attachment directory patient_id: patient ID (used for auditing) content_type: HTTP content type; see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type offered_filename: filename offered to user guess_content_type: if no content_type is specified, should we guess? Pass ``None`` for the default, :data:`DEFAULT_GUESS_CONTENT_TYPE`. """ # noqa qparams = { UrlKeys.PATIENT_ID: patient_id, UrlKeys.FILENAME: filename, } if content_type: qparams[UrlKeys.CONTENT_TYPE] = content_type if offered_filename: qparams[UrlKeys.OFFERED_FILENAME] = offered_filename if guess_content_type is not None: qparams[UrlKeys.GUESS_CONTENT_TYPE] = int(guess_content_type) filepath = get_archive_attachment_filepath(filename) add_file_timestamp_to_url_query(filepath, qparams) return url_with_querystring( reverse(UrlNames.ARCHIVE_ATTACHMENT), **qparams)