Esempio n. 1
0
def mkb(request):
    """ Отчет заболеваний МКБ за период """
    period_form = PeriodForm(request.GET)
    
    data = {'period_form': period_form, 'is_have_result': False}
    if len(request.GET) == 0:
        # Если поиск не запускали, то и не надо показывать всех пациентов
        data['period_form'] = PeriodForm()
        return render_to_response('analytic/mkb.html', data,
                              context_instance=RequestContext(request))

    
    if period_form.is_valid():
        start = period_form.cleaned_data['period_start']
        end = period_form.cleaned_data['period_end']
        date_range = (start, end + timedelta(days=1))
        qs = Diagnosis.objects.filter(date_created__range=date_range) \
                              .values('patient__full_name', 'code', 'name') \
                              .order_by('code', 'name', 'patient__full_name')
        data.update({'info': qs,
                     'is_have_result': True})
    else:
        data.update({'info': []})

    return render_to_response('analytic/mkb.html',
                              data,
                              context_instance=RequestContext(request))
Esempio n. 2
0
def visit(request):
    """ Отчет по количеству посещений МО за период """
    period_form = PeriodForm(request.GET)
    
    data = {'period_form': period_form, 'is_have_result': False}
    if len(request.GET) == 0:
        # Если поиск не запускали, то и не надо показывать всех пациентов
        data['period_form'] = PeriodForm()
        return render_to_response('analytic/visit.html', data,
                              context_instance=RequestContext(request))

    
    if period_form.is_valid():
        start = period_form.cleaned_data['period_start']
        end = period_form.cleaned_data['period_end']
        date_range = (start, end + timedelta(days=1))
        qs = Visit.objects.filter(date_created__range=date_range) \
                          .values('name') \
                          .annotate(count=Count('pk')) \
                          .order_by('name')
        data.update({'info': qs,
                     'is_have_result': True,
                     'period_start': start,
                     'period_end': end})
    else:
        data.update({'info': []})

    return render_to_response('analytic/visit.html',
                              data,
                              context_instance=RequestContext(request))
Esempio n. 3
0
def nosology(request):
    """ Отчет по нозологиям за период """
    period_form = PeriodForm(request.GET)
    
    data = {'period_form': period_form, 'is_have_result': False}
    if len(request.GET) == 0:
        # Если поиск не запускали, то и не надо показывать всех пациентов
        data['period_form'] = PeriodForm
        return render_to_response('analytic/nosology.html', data,
                              context_instance=RequestContext(request))

    
    if period_form.is_valid():
        start = period_form.cleaned_data['period_start']
        end = period_form.cleaned_data['period_end']
        type_residence = period_form.cleaned_data.get('type_residence')
        
        date_range = (start, end + timedelta(days=1))
        death_cnd = Q(death__gt=start) | Q(death__isnull=True)
        patient_qs = Patient.objects.filter(death_cnd,
                                            type=Patient.PROBAND,
                                            birthday__lt=date_range[1])
        # ищем в истории место пребывания
        if type_residence:
            if start == date.today():
                patient_qs = qs.filter(type_residence=type_residence)
            else:
                pks = get_type_residence_qs(type_residence, start, end)
                patient_qs = patient_qs.filter(pk__in=pks)
                res_info = dict(Patient.TYPE_RESIDENCES)
                data['type_residence'] = res_info.get(int(type_residence), '')

        diagnosis_qs = Diagnosis.objects.filter(patient__in=patient_qs) \
                                        .select_related('patient')
        marriageble_birthday = start - MARRIAGEABLE_AGE
        info = {}
        for diagnosis in diagnosis_qs:
            code = diagnosis.code
            if code not in info:
                # название, код, кол-во детей, кол-во взрослых
                info[code] = [diagnosis.name, diagnosis.code, 0, 0]
            if diagnosis.patient.birthday < marriageble_birthday:
                info[code][2] += 1
            else:
                info[code][3] += 1
        info = info.values()
        info.sort(lambda x, y: cmp(x[0], y[0]))
        
        data.update({'info': info,
                     'is_have_result': True,
                     'period_start': start,
                     'period_end': end})
    else:
        data.update({'children': '-',
                     'marriageable': '-',
                     'fetus': '-'})

    return render_to_response('analytic/nosology.html',
                              data,
                              context_instance=RequestContext(request))
Esempio n. 4
0
def life(request):
    """ Отчет количества живых пациентов по возрастам за период """
    period_form = PeriodForm(request.GET)
    
    data = {'period_form': period_form, 'is_have_result': False}
    if len(request.GET) == 0:
        # Если поиск не запускали, то и не надо показывать всех пациентов
        data['period_form'] = PeriodForm
        return render_to_response('analytic/life.html', data,
                              context_instance=RequestContext(request))

    
    if period_form.is_valid():
        start = period_form.cleaned_data['period_start']
        end = period_form.cleaned_data['period_end']
        type_residence = period_form.cleaned_data.get('type_residence')
        
        death_cnd = Q(death__gt=start) | Q(death__isnull=True)
        qs = Patient.objects.filter(death_cnd) \
                            .exclude(type=Patient.FAMILY_MEMBER)
        # ищем в истории место пребывания
        if type_residence:
            if start == date.today():
                qs = qs.filter(type_residence=type_residence)
            else:
                pks = get_type_residence_qs(type_residence, start, end)
                qs = qs.filter(pk__in=pks)
                res_info = dict(Patient.TYPE_RESIDENCES)
                data['type_residence'] = res_info.get(int(type_residence), '')

        marriageble_birthday = start - MARRIAGEABLE_AGE
        childrens = qs.filter(birthday__gt=marriageble_birthday,
                              birthday__lte=end,
                              type=Patient.PROBAND)
        marriageable = qs.filter(Q(birthday__lte=marriageble_birthday),
                                 type=Patient.PROBAND,
                                 birthday__lte=end)
        fetus_cnd = Q(type=Patient.FETUS) | \
                    (Q(birthday__gt=F('date_registration')) & Q(birthday__gt=end))
        reg_date = end + timedelta(days=1)
        fetus = qs.filter(fetus_cnd, date_registration__lte=reg_date)
        data.update({'children': childrens.count(),
                     'marriageable': marriageable.count(),
                     'fetus': fetus.count(),
                     'is_have_result': True,
                     'period_start': start,
                     'period_end': end})
    else:
        data.update({'children': '-',
                     'marriageable': '-',
                     'fetus': '-'})

    return render_to_response('analytic/life.html',
                              data,
                              context_instance=RequestContext(request))
Esempio n. 5
0
def selectcategory():

    mytoken = session.get('mytoken')

    form = PeriodForm()

    if form.validate_on_submit():
        session['inicio'] = form.inicio.data
        session['fim'] = form.fim.data
        flash(f'Período selecionado com sucesso!', 'success')
        return redirect(url_for('loginpostgis', mytoken=session['mytoken']))
    else:
        flash(
            'Camada inválida. Selecione uma camada de pontos válida do Survey.',
            'danger')

    return render_template('selectcategory.html',
                           title='SelectCategory',
                           mytoken=mytoken,
                           form=form)
Esempio n. 6
0
def statistics(request):
    """
    тип графика
    название графика
    массив название
    массив данных
    подпись по x
    подпись по y
    """
    chart_type = 'column'
    chart_title = u'Название графика'
    row_title = u'Параметр'
    y_title = u'Ось Y'

    statistics = request.GET.get('statistics', 'requests')

    catalogs = ZCatalog.objects.all()
    start_date = datetime.datetime.now()
    end_date = datetime.datetime.now()
    date_group = u'2'  # группировка по дням
    attributes = []

    period_form = PeriodForm()
    group_form = GroupForm()
    attributes_form = AttributesForm()
    catalog_form = ZCatalogForm()
    if request.method == 'POST':
        period_form = PeriodForm(request.POST)
        group_form = GroupForm(request.POST)
        attributes_form = AttributesForm(request.POST)
        catalog_form = ZCatalogForm(request.POST)

        if period_form.is_valid():
            start_date = period_form.cleaned_data['start_date']
            end_date = period_form.cleaned_data['end_date']

        if group_form.is_valid():
            date_group = group_form.cleaned_data['group']

        if attributes_form.is_valid():
            attributes = attributes_form.cleaned_data['attributes']

        if catalog_form.is_valid():
            catalogs = catalog_form.cleaned_data['catalogs']

    if statistics == 'requests':
        attributes_form = None
        rows = requests_count(start_date=start_date,
                              end_date=end_date,
                              group=date_group,
                              catalogs=catalogs)
        chart_title = u'Число поисковых запросов по дате'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'

    elif statistics == 'attributes':
        group_form = None
        rows = requests_by_attributes(start_date=start_date,
                                      end_date=end_date,
                                      attributes=attributes,
                                      catalogs=catalogs)

        chart_title = u'Число поисковых запросов по поисковым атрибутам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'

    elif statistics == 'terms':
        group_form = None
        rows = requests_by_term(start_date=start_date,
                                end_date=end_date,
                                attributes=attributes,
                                catalogs=catalogs)

        chart_title = u'Число поисковых запросов по фразам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'
    else:
        return HttpResponse(u'Неправильный тип статистики')

    data_rows = json.dumps(rows, ensure_ascii=False)

    return render(
        request, 'zgate/administration/zcatalog_statistics.html', {
            'data_rows': data_rows,
            'catalog_form': catalog_form,
            'period_form': period_form,
            'group_form': group_form,
            'attributes_form': attributes_form,
            'chart_type': chart_type,
            'chart_title': chart_title,
            'y_title': y_title,
            'row_title': row_title,
            'active_module': 'zgate'
        })
Esempio n. 7
0
def statistics(request, catalog=None):
    """
    тип графика
    название графика
    массив название
    массив данных
    подпись по x
    подпись по y
    """
    chart_type = 'column'
    chart_title = u'Название графика'
    row_title = u'Параметр'
    y_title = u'Ось Y'

    statistics = request.GET.get('statistics', 'requests')
    catalogs = []
    if not catalog:
        catalogs += ['sc2', 'ebooks']
    else:
        catalogs.append(catalog)
    # catalogs = ZCatalog.objects.all()
    start_date = datetime.datetime.now()
    end_date = datetime.datetime.now()
    date_group = u'2'  # группировка по дням
    attributes = []

    period_form = PeriodForm()
    group_form = GroupForm()
    attributes_form = AttributesForm()
    catalog_form = CatalogForm()
    if request.method == 'POST':
        period_form = PeriodForm(request.POST)
        group_form = GroupForm(request.POST)
        attributes_form = AttributesForm(request.POST)
        catalog_form = CatalogForm(request.POST)

        if period_form.is_valid():
            start_date = period_form.cleaned_data['start_date']
            end_date = period_form.cleaned_data['end_date']

        if group_form.is_valid():
            date_group = group_form.cleaned_data['group']

        if attributes_form.is_valid():
            attributes = attributes_form.cleaned_data['attributes']

        if catalog_form.is_valid():
            catalogs = catalog_form.cleaned_data['catalogs']

    if statistics == 'requests':
        attributes_form = None
        rows = requests_count(
            start_date=start_date,
            end_date=end_date,
            group=date_group,
            catalogs=catalogs
        )
        chart_title = u'Число поисковых запросов по дате'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'

    elif statistics == 'attributes':
        group_form = None
        rows = requests_by_attributes(
            start_date=start_date,
            end_date=end_date,
            attributes=attributes,
            catalogs=catalogs
        )

        chart_title = u'Число поисковых запросов по поисковым атрибутам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'

    elif statistics == 'terms':
        group_form = None
        rows = requests_by_term(
            start_date=start_date,
            end_date=end_date,
            attributes=attributes,
            catalogs=catalogs
        )

        chart_title = u'Число поисковых запросов по фразам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'
    else:
        return HttpResponse(u'Неправильный тип статистики')

    data_rows = json.dumps(rows, ensure_ascii=False)

    return render(request, 'ssearch/administration/statistics.html', {
        'data_rows': data_rows,
        'catalog_form': catalog_form,
        'period_form': period_form,
        'group_form': group_form,
        'attributes_form': attributes_form,
        'chart_type': chart_type,
        'chart_title': chart_title,
        'y_title': y_title,
        'row_title': row_title,
        'active_module': 'zgate'
    })