Beispiel #1
0
def save_doc_form4(request, type, id_doc, mode_comment):
    ''' Сохранить запись Document + комментарий с новой записью в комментрии с действием пользователя
        Установить собственый параментрв DOCx,set_fields_formx, is_valid_formx
    ''' 
    return save_doc(Doc4,set_fields_form4, is_valid_form4, request, type, id_doc, mode_comment)
Beispiel #2
0
def save_doc_form1(request, type, id_doc, mode_comment):
    ''' Сохранить запись Document + комментарий с новой записью в комментрии с действием пользователя
        Установить собственый параментрв DOCx,set_fields_formx, is_valid_formx
    ''' 
    return save_doc(Doc1,set_fields_form1, is_valid_form1, request, type, id_doc, mode_comment)
Beispiel #3
0
def monitoring_form(request, question_id):
    if not request.user.is_authenticated():
        return redirect('/auth/login')

    gid = get_ids(question_id)
    type = int(gid[0])

    #   Определение доступа
    usr = auth.get_user(request)
    try:
        role = Role.objects.get(user=usr, type=type)
    except ObjectDoesNotExist:
        html_response_err = 'medicament/error_access.html'
        return render_to_response(html_response_err, {})

# Разделим question id на части     xxx,yyy,zzz где xxx - тип мониторинга, yyy - номер страницы paginator - для возвращения на страницу
# zzz - сквозной номре документв

    doc_id = gid[1]
    if len(gid) == 7:
        page_number = int(gid[2])
        m = int(gid[3])
        period = int(gid[4])
        status = gid[5]
        region = int(gid[6])
    else:
        #       assert False
        page_number = 1
        m = 0
        period = 0
        status = '0'
        region = 0

    if role.role == "F":
        see_all = True  # see_all  контроль и создание новых отчетов
        user_hosp = 0
        see_admin = True
    elif role.role == "К":
        see_all = True  # see_all  контроль и создание новых отчетов
        user_hosp = 0
        see_admin = False
    else:
        see_all = False
        user_hosp = role.hosp
        see_admin = False

# Настройка типа документа
    if type == 1:
        doc = Doc1
        save_doc = save_doc_form1
        html_response = "medicament/doc_form1.html"
        export_to_excel = exp_to_excel_form1
    elif type == 2:
        doc = Doc2
        save_doc = save_doc_form2
        html_response = "medicament/doc_form2.html"
        export_to_excel = exp_to_excel_form2
    elif type == 3:
        doc = Doc3
        save_doc = save_doc_form3
        html_response = "medicament/doc_form3.html"
        export_to_excel = exp_to_excel_form3
## конец настройки по типам!

    args = {}
    args.update(csrf(request))
    isOk = True
    actionComment = Comment.EMPTY
    error = ''
    ret_mess = [True, 'OK']

    if request.POST:
        if 'button_load' in request.POST:
            #            assert False
            #            load_from_excel(request, question_id)
            response = redirect('/load/' + str(type) + ',' + str(doc_id) + ','+ str(page_number) + ',' + str(m) \
                                + ',' + str(period) + ',' + status + ',' + str(region))
            return response
        if 'button_addComment' in request.POST:
            add_comment(request, question_id)  #
            mode_comment = False
        else:
            mode_comment = True
        if 'button_export' in request.POST:  # Кнопка Export доступна во всех режимах, поэтому работает без сохранения
            args['doc'] = doc.objects.filter(
                pk=doc_id
            )  # выбор документа фильтром с списке, чтобы функция вывода в excel работала единообразно
            odoc = args['doc'][0]
            file_name = export_to_excel(args['doc'], odoc.period.id, region, 1)
            return redirect("/monitor/export/" + file_name)

        if not 'button_load' in request.POST:
            ret_mess = save_doc(request, type, doc_id, mode_comment)

        if ret_mess[0]:  # проверка прошла нормально
            if 'button_export' in request.POST:  # Эта ветка на память, сюда не должна попадать
                args['doc'] = doc.objects.filter(pk=doc_id)
                file_name = export_to_excel(args['doc'], doc.period, region, 1)
                return redirect("/monitor/export/" + file_name)
            else:
                response = redirect('/form/' + str(type) + ',' +  str(page_number) + ',' + str(m) \
                                + ',' + str(period) + ',' + status + ',' + str(region))
                return response
        else:
            args['doc'] = doc.objects.get(pk=doc_id)
            #            error = "Сумма по столбцам превышает итог"
            error = ret_mess[1]
    else:  # Первый вход по GET
        args['doc'] = doc.objects.get(pk=doc_id)
# во всех случаях
    args['doc_type'] = Doc_type.objects.get(pk=type)
    # ищем документ предыдущего периода
    doc_prevList = doc.objects.filter(period=args['doc'].period.prev,
                                      hosp=args['doc'].hosp)
    if doc_prevList:
        args['doc_prev'] = doc_prevList[0]
# для визуального контроля

    args['first_name'] = auth.get_user(request).first_name

    args['right_operator'] = not see_all
    args['right_control'] = see_all
    args['right_admin'] = see_admin

    args['isOk'] = isOk
    args['error'] = error
    args['page_number'] = page_number  # для пагинации

    comment_form = CommentForm
    args['comment'] = Comment.objects.filter(document=doc_id)
    args['form'] = comment_form

    args['period'] = period
    args['status'] = status
    args['hosp'] = m
    args['region'] = region
    args['doc_id'] = doc_id
    args['type'] = type

    # Настройка типа документа
    if type == 3:
        args['t1000'] = Doc3Tab1000.objects.filter(doc=doc_id)
        args['t2000'] = Doc3Tab2000.objects.filter(doc=doc_id)
        args['t3000'] = Doc3Tab3000.objects.filter(doc=doc_id)
        args['t4000'] = Doc3Tab4000.objects.filter(doc=doc_id)
        args['t5000'] = Doc3Tab5000.objects.filter(doc=doc_id)
        args['t5001'] = Doc3Tab5001.objects.filter(doc=doc_id)
        args['t6000'] = Doc3Tab6000.objects.filter(doc=doc_id)
        args['t7000'] = Doc3Tab7000.objects.filter(doc=doc_id)
        if doc_prevList:
            args['p1000'] = Doc3Tab1000.objects.filter(doc=doc_prevList[0])
            args['p2000'] = Doc3Tab2000.objects.filter(doc=doc_prevList[0])
            args['p3000'] = Doc3Tab3000.objects.filter(doc=doc_prevList[0])
            args['p4000'] = Doc3Tab4000.objects.filter(doc=doc_prevList[0])
            args['p5000'] = Doc3Tab5000.objects.filter(doc=doc_prevList[0])
            args['p5001'] = Doc3Tab5001.objects.filter(doc=doc_prevList[0])
            args['p6000'] = Doc3Tab6000.objects.filter(doc=doc_prevList[0])
            args['p7000'] = Doc3Tab7000.objects.filter(doc=doc_prevList[0])
            args['doc_prev'] = doc_prevList[0]


# конец настройки по типу документа
    return render_to_response(html_response, args)
Beispiel #4
0
def monitoring_form(request, question_id):
    if not request.user.is_authenticated():
        return redirect('/auth/login')

    gid = get_ids(question_id)   
    type = int(gid[0])
    
#   Определение доступа
    usr =  auth.get_user(request)
    try:
        role = Role.objects.get(user=usr,type=type);
    except ObjectDoesNotExist:
        html_response_err = 'medicament/error_access.html'      
        return render_to_response(html_response_err, {})


# Разделим question id на части     xxx,yyy,zzz где xxx - тип мониторинга, yyy - номер страницы paginator - для возвращения на страницу
# zzz - сквозной номре документв

    doc_id = gid[1]
    if len(gid) == 7:
        page_number = int(gid[2])
        m = int(gid[3])  
        period = int(gid[4])
        status = gid[5]
        region = int(gid[6])
    else:
#       assert False
        page_number=1  
        m = 0  
        period = 0
        status = '0'
        region = 0

    if role.role == "F":
        see_all = True                # see_all  контроль и создание новых отчетов
        user_hosp = 0
        see_admin = True
    elif role.role == "К":
        see_all = True                # see_all  контроль и создание новых отчетов
        user_hosp = 0
        see_admin = False
    else:
        see_all = False
        user_hosp = role.hosp
        see_admin = False


# Настройка типа документа  
    if type == 1:
        doc = Doc1
        save_doc = save_doc_form1
        html_response = "medicament/doc_form1.html"
        export_to_excel = exp_to_excel_form1
    elif type == 2: 
        doc = Doc2
        save_doc = save_doc_form2
        html_response = "medicament/doc_form2.html"
        export_to_excel = exp_to_excel_form2
    elif type == 3: 
        doc = Doc3
        save_doc = save_doc_form3
        html_response = "medicament/doc_form3.html"
        export_to_excel = exp_to_excel_form3
    elif type == 4: 
        doc = Doc4
        save_doc = save_doc_form4
        html_response = "medicament/doc_form4.html"
        export_to_excel = exp_to_excel_form4
## конец настройки по типам!
                   
    args = {}
    args.update(csrf(request))
    isOk = True 
    actionComment =  Comment.EMPTY
    error = ''
    ret_mess = [True,'OK']
    
    if request.POST:
        if  'button_load' in request.POST:
            response = redirect('/loadExcel/' + str(type) + ',' + str(doc_id) + ','+ str(page_number) + ',' + str(m) \
                                + ',' + str(period) + ',' + status + ',' + str(region))
            return response
        if  'button_addComment' in request.POST:
            add_comment(request, question_id)    # 
            mode_comment = False
        else:
            mode_comment = True
        if  'button_export' in request.POST:                 # Кнопка Export доступна во всех режимах, поэтому работает без сохранения
            args['doc']    =  doc.objects.filter(pk=doc_id)  # выбор документа фильтром с списке, чтобы функция вывода в excel работала единообразно
            odoc = args['doc'][0];
            file_name = export_to_excel(args['doc'],odoc.period.id,region,1) 
            return redirect("/monitor/export/" + file_name)

        if  not 'button_load' in request.POST:
            ret_mess = save_doc(request,type,doc_id, mode_comment)
                    
        if ret_mess[0]:  # проверка прошла нормально
            if  'button_export' in request.POST:             # Эта ветка на память, сюда не должна попадать
                args['doc']    =  doc.objects.filter(pk=doc_id)
                file_name = export_to_excel(args['doc'], doc.period,region,1) 
                return redirect("/monitor/export/" + file_name)
            else:      
                response = redirect('/form/' + str(type) + ',' +  str(page_number) + ',' + str(m) \
                                + ',' + str(period) + ',' + status + ',' + str(region))
                return response
        else:
            args['doc']    =  doc.objects.get(pk=doc_id)
#            error = "Сумма по столбцам превышает итог"  
            error = ret_mess[1]
    else:   # Первый вход по GET
        args['doc']    =  doc.objects.get(pk=doc_id)            
# во всех случаях    
    args['doc_type']  =  Doc_type.objects.get(pk=type)
# ищем документ предыдущего периода 
    doc_prevList = doc.objects.filter(period = args['doc'].period.prev , hosp = args['doc'].hosp)
    if doc_prevList:
        args['doc_prev'] = doc_prevList[0]
# для визуального контроля

    args['username'] = auth.get_user(request).username   
    args['first_name'] = auth.get_user(request).first_name    

    args['right_operator'] = not see_all       
    args['right_control'] = see_all       
    args['right_admin']   = see_admin
           
    args['isOk'] = isOk  
    args['error']   =  error     
    args['page_number']   =  page_number       # для пагинации     
    
    comment_form = CommentForm      
    args['comment']  =  Comment.objects.filter(document = doc_id)            
    args['form']     =  comment_form     
  
    args['period'] = period       
    args['status'] = status       
    args['hosp'] = m       
    args['region'] = region       
    args['doc_id'] = doc_id       

# Настройка типа документа  
    if type == 1:
        args['isloadExcel'] = True        
    if type == 4:
        args['tab1000'] = Doc4Tab1000.objects.filter(doc=doc_id)       
        args['tab2000'] = Doc4Tab2000.objects.filter(doc=doc_id)
        args['isloadExcel'] = True        
#        
# конец настройки по типу документа
    return render_to_response(html_response, args)