Exemple #1
0
def account_settings():
    """
    Shows the account settings page.
    """
    if request.method == 'GET':
        current_app.logger.warning("GET called")
        return render_template('homepage/account_settings.html',
                               content=g.config['TECHNICAL_CONFIG'],
                               week=c.api('/epi_week'))

    elif request.method == 'POST':
        url = current_app.config['INTERNAL_AUTH_ROOT'] + "/api/update_user"
        r = requests.post(url, json=request.json)
        return (r.text, r.status_code, r.headers.items())
Exemple #2
0
def index(locID=None):
    """
    Render the reports splash page (index.html).
    The reports splash page provides a form enabling user to select which
    report to view.

    Args:
        locID (int): The location ID of a location to be automatically loaded
            into the location selector.
    """
    locID = g.allowed_location if not locID else locID
    return render_template('reports/index.html',
                           content=g.config['REPORTS_CONFIG'],
                           loc=locID,
                           week=c.api('/epi_week'))
Exemple #3
0
def wait():
    if "url" in request.args.keys():
        url = request.args["url"]
    else:
        abort(500, "Did not get a url")
    url = url.replace("'", "%27")

    if request.args.get('start_date'):
        url += '&start_date=' + request.args['start_date']
    if request.args.get('end_date'):
        url += '&end_date=' + request.args['end_date']

    return render_template('download/wait.html',
                           content=g.config['DOWNLOAD_CONFIG'],
                           api_url=url,
                           week=c.api('/epi_week'))
Exemple #4
0
def create_report(config,
                  report=None,
                  location=None,
                  end_date=None,
                  start_date=None):
    """
    Dynamically creates report, that can then be served either in HTML or
    PDF format.

    Args:
        config (dict): The current app config object.
        report (str): The report ID, from the REPORTS_LIST configuration
            file parameter.
        location (int): The location ID for the location used to filter the
            report's data.
        end_date (str): The end_data used to filter the report's data, in
            ISO format.
        start_date (str): The start_date used to filter the report's data,
            in ISO format.

    Returns:
        dict: The report details
            ::
            {
               'template' (str): the template file specified in the
                    REPORTS_LIST config property,
               'report' (dict): the data collected form the Meerkat API,
               'extras' (dict): any extra data calulated from API data
                    needed to create the report,
               'address' (str): the contact address to be printed in the
                    report
            }
    """

    # try:
    report_list = current_app.config['REPORTS_CONFIG']['report_list']
    access = report_list[report].get('access', '')

    # Default location
    if not location:
        location = current_app.config['REPORTS_CONFIG']['default_location']

    # Abort if the location is not allowed
    allowedLocations = report_list[report].get('locations', None)
    if allowedLocations and int(location) not in allowedLocations:
        abort(400,
              "Report not available for location (id: {})".format(location))

    # Restrict report access as specified in configs.
    if access and access not in g.payload['acc']:
        auth.check_auth([access],
                        [current_app.config['SHARED_CONFIG']['auth_country']])

    api_request = '/reports'
    api_request += '/' + report_list[report]['api_name']
    if location is not None:
        api_request += '/' + str(location)
    app.logger.debug('setting start date and end date')
    if start_date is None and end_date is None:
        if "default_period" in report_list[report].keys():
            period = report_list[report]["default_period"]
            today = datetime.today()
            app.logger.debug('Default period specified')
            if period == "week":
                app.logger.debug('Default period is week')
                epi_week = c.api('/epi_week')
                # Calulation for start date is: month_day - ( week_day-week_offset % 7) - 7
                # The offset is the #days into the current epi week.
                offset = (today.weekday() - epi_week["offset"]) % 7
                # Start date is today minus the offset minus one week.
                start_date = datetime(today.year, today.month,
                                      today.day) - timedelta(days=offset + 7)
                app.logger.debug('start date is ' + str(start_date))
                # End date is today minus the offset, minus 1 day (because our end date is "inclusive")
                end_date = datetime(today.year, today.month,
                                    today.day) - timedelta(days=offset + 1)
                app.logger.debug('start date is ' + str(end_date))
            elif period == "month":
                start_date = datetime(
                    today.year, today.month,
                    1) - dateutil.relativedelta.relativedelta(months=1)
                end_date = datetime(today.year, today.month,
                                    1) - timedelta(days=1)
            elif period == "year":
                start_date = datetime(today.year, 1, 1)
                end_date = datetime(today.year, today.month, today.day)
            if start_date and end_date:
                start_date = start_date.isoformat()
                end_date = end_date.isoformat()  # To include the the end date

    if (end_date is not None):
        api_request += '/' + end_date
    if (start_date is not None):
        api_request += '/' + start_date

    params = None
    if report in ["communicable_diseases"]:
        if "central_review" in config["TECHNICAL_CONFIG"] and config[
                "TECHNICAL_CONFIG"]["central_review"]:
            params = "central_review"
        else:
            params = None

    app.logger.debug('Getting data')
    data = c.api(api_request, params=params)
    data["flag"] = config["FLAGG_ABR"]

    if report in [
            'public_health', 'cd_public_health', "ncd_public_health", "cerf"
    ]:
        # Extra parsing for natural language bullet points
        extras = {"patient_status": {}}
        extras["patient_status"]["national"] = {'percent': 0, 'quantity': 0}
        extras["patient_status"]["refugee"] = {'percent': 0, 'quantity': 0}

        for item in data['data']['patient_status']:
            title = item['title'].lower().replace(" ", "")
            if title not in ["refugee", "other"]:
                title = "national"
            extras["patient_status"][title] = {
                'percent': item['percent'],
                'quantity': item['quantity']
            }
        extras['map_centre'] = report_list[report].get('map_centre', ())
        extras['reg_data'] = c.api("/geo_shapes/region")
        extras['dis_data'] = c.api("/geo_shapes/district")
    elif report in ['oms', 'plague', 'ctc', 'sc']:
        extras = {}
        extras['map_centre'] = report_list[report]['map_centre']
        extras['reg_data'] = c.api("/geo_shapes/region")
        extras['dis_data'] = c.api("/geo_shapes/district")
    else:
        extras = None

    # Render correct template for the report
    return {
        'report':
        data,
        'extras':
        extras,
        'address':
        current_app.config["REPORTS_CONFIG"]["address"],
        'template':
        report_list[report]['template'],
        'template_email_html':
        report_list[report].get('template_email_html', None),
        'template_email_plain':
        report_list[report].get('template_email_plain', None)
    }
Exemple #5
0
def index():
    return render_template('download/index.html',
                           content=g.config['DOWNLOAD_CONFIG'],
                           week=c.api('/epi_week'))