Skip to content

Commit

Permalink
Merge pull request #3782 from mikhailprivalov/accountRegister
Browse files Browse the repository at this point in the history
Account register
  • Loading branch information
Wellheor1 authored May 3, 2024
2 parents 085e0bc + 5f01d7d commit fbc2fa0
Show file tree
Hide file tree
Showing 18 changed files with 786 additions and 7 deletions.
Empty file added api/contracts/__init__.py
Empty file.
155 changes: 155 additions & 0 deletions api/contracts/func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
from clients.models import CardBase
from contracts.models import BillingRegister
from contracts.sql_func import get_research_coast_by_prce, get_data_for_conform_billing
from directions.models import IstochnikiFinansirovaniya
from statistic.sql_func import statistics_research_by_hospital_for_external_orders
from statistic.views import get_price_hospital


def researches_for_billing(type_price, company_id, date_start, date_end):
sql_result = None
research_coast = {}
price = None
if type_price == "Заказчик":
hospital_id = company_id
price = get_price_hospital(hospital_id, date_start, date_end)
base = CardBase.objects.filter(internal_type=True).first()
finsource = IstochnikiFinansirovaniya.objects.filter(base=base, title__in=["Договор"], hide=False).first()
sql_result = statistics_research_by_hospital_for_external_orders(date_start, date_end, hospital_id, finsource.pk)
coast_research_price = get_research_coast_by_prce((price.pk,))
research_coast = {coast.research_id: float(coast.coast) for coast in coast_research_price}
result = {}
iss_data = set()
if sql_result:
for i in sql_result:
iss_data.add(i.iss_id)
current_data = {
"research_id": i.research_id,
"research_title": i.research_title,
"date_confirm": i.date_confirm,
"patient_fio": f"{i.patient_family} {i.patient_name} {i.patient_patronymic}",
"patient_born": i.ru_date_born,
"tube_number": i.tube_number,
"coast": research_coast.get(i.research_id, 0),
"code_nmu": i.code_nmu,
"internal_code": i.internal_code,
}
if not result.get(i.patient_card_num):
result[i.patient_card_num] = [current_data.copy()]
else:
result[i.patient_card_num].append(current_data.copy())
return {"result": result, "issIds": list(iss_data), "priceId": price.pk}


def get_confirm_data_for_billing(price_id, billing_id):
sql_result = get_data_for_conform_billing(billing_id)
coast_research_price = get_research_coast_by_prce((price_id,))
research_coast = {coast.research_id: float(coast.coast) for coast in coast_research_price}
result = {}
iss_data = set()
for i in sql_result:
iss_data.add(i.iss_id)
current_data = {
"research_id": i.research_id,
"research_title": i.research_title,
"date_confirm": i.date_confirm,
"patient_fio": f"{i.patient_family} {i.patient_name} {i.patient_patronymic}",
"patient_born": i.ru_date_born,
"tube_number": i.tube_number,
"coast": research_coast.get(i.research_id, 0),
}
if not result.get(i.patient_card_num):
result[i.patient_card_num] = [current_data.copy()]
else:
result[i.patient_card_num].append(current_data.copy())
billing_register_data = BillingRegister.objects.filter(id=billing_id).first()
company_title = billing_register_data.company.title if billing_register_data.company else ""
hospital_title = billing_register_data.hospital.title if billing_register_data.hospital else ""
organization = {
"company": company_title,
"hospital": hospital_title,
"create_at": billing_register_data.create_at,
"who_create": billing_register_data.who_create.get_fio(),
"date_start": billing_register_data.date_start,
"date_end": billing_register_data.date_end,
"info": billing_register_data.info,
"is_confirmed": billing_register_data.is_confirmed,
}
return {"result": result, "issIds": list(iss_data), "organization": organization}


def structure_table(data_researches):
columns = [
{"key": "serialNumber", "field": "serialNumber", "title": "№", "align": "left", "width": 30, "fixed": "left"},
{"key": "patientFio", "field": "patientFio", "title": "Пациент", "align": "left", "width": 200, "fixed": "left"},
{"key": "patientBirthDay", "field": "patientBirthDay", "title": "Дата рожд.", "align": "left", "width": 50, "fixed": "left"},
{"key": "executeDate", "field": "executeDate", "title": "Дата вып.", "align": "left", "width": 50, "fixed": "left"},
{"key": "internalId", "field": "internalId", "title": "Код", "align": "left", "width": 100, "fixed": "left"},
{"key": "codeNMU", "field": "codeNMU", "title": "Код НМУ", "align": "left", "width": 120, "fixed": "left"},
{"key": "researchTitle", "field": "researchTitle", "title": "Наименование услуги", "align": "left", "width": 150, "fixed": "left"},
{"key": "tubeNumber", "field": "tubeNumber", "title": "Лаб. номер", "align": "left", "width": 100, "fixed": "left"},
{"key": "count", "field": "count", "title": "Кол.", "align": "left", "width": 50, "fixed": "left"},
{"key": "coast", "field": "coast", "title": "Цена", "align": "left", "width": 50, "fixed": "left"},
{"key": "summ", "field": "summ", "title": "Стоимость, руб", "align": "left", "width": 50, "fixed": "left"},
]
step = 0
patient_data = {}
prev_card_id_patient = -1
total = 0
for card_id, research_data in data_researches.get("result").items():
step += 1
sum_patient = 0
for i in research_data:
if (prev_card_id_patient != -1) and (card_id != prev_card_id_patient):
patient_data[f"{prev_card_id_patient} summ"] = {
"serialNumber": "",
"patientFio": "Сумма по пациенту:",
"patientBirthDay": "",
"tubeNumber": "",
"coast": "",
"researchTitle": "",
"internalId": "",
"codeNMU": "",
"summ": sum_patient,
}
if not patient_data.get(card_id):
patient_data[card_id] = {
"serialNumber": step,
"patientFio": i.get("patient_fio"),
"patientBirthDay": i.get("patient_born"),
"tubeNumber": i.get("tube_number"),
"coast": i.get("coast"),
"researchTitle": i.get("research_title"),
"internalId": i.get("internal_code"),
"codeNMU": i.get("code_nmu"),
"summ": "",
}
else:
patient_data[f"{card_id} {i.get('research_id')}"] = {
"serialNumber": "",
"patientFio": "",
"patientBirthDay": "",
"tubeNumber": i.get("tube_number"),
"coast": i.get("coast"),
"researchTitle": i.get("research_title"),
"internalId": i.get("internal_code"),
"codeNMU": i.get("code_nmu"),
"summ": "",
}
sum_patient += i.get("coast")
total += i.get("coast")
prev_card_id_patient = card_id
patient_data["total"] = {
"serialNumber": "",
"patientFio": "Итого",
"patientBirthDay": "",
"tubeNumber": "",
"coast": "",
"researchTitle": "",
"internalId": "",
"codeNMU": "",
"summ": total,
}

table_data = [v for v in patient_data.values()]
return {"columns": columns, "tableData": table_data}
11 changes: 11 additions & 0 deletions api/contracts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path

from . import views

urlpatterns = [
path('create-billing', views.create_billing),
path('update-billing', views.update_billing),
path('confirm-billing', views.confirm_billing),
path('get-billings', views.get_billings),
path('get-billing', views.get_billing),
]
86 changes: 86 additions & 0 deletions api/contracts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
import simplejson as json
from django.db import transaction

from api.contracts.func import researches_for_billing, get_confirm_data_for_billing, structure_table
from contracts.models import BillingRegister, RawDocumentBillingRegister
from directions.models import Issledovaniya
from directory.models import Researches
from laboratory.decorators import group_required
from utils.response import status_response


@login_required
@group_required("Счет: проект")
def create_billing(request):
body = json.loads(request.body)
company_id = body.get("companyId")
hospital_id = body.get("hospitalId")
date_start = body.get("dateStart")
date_end = body.get("dateEnd")
info = body.get("info")
billing_id = BillingRegister.create_billing(company_id, hospital_id, date_start, date_end, info)
return JsonResponse({"ok": True, "billingInfo": billing_id})


@login_required
@group_required("Счет: проект")
def update_billing(request):
body = json.loads(request.body)
hospital_id = body.get("hospitalId")
date_start = body.get("dateStart")
date_end = body.get("dateEnd")
billing_id = body.get("id")
info = body.get("info")
billing_info = BillingRegister.update_billing(billing_id, date_start, date_end, info)
type_price = body.get("typeCompany")
data = researches_for_billing(type_price, hospital_id, date_start, date_end)
structure_data = structure_table(data)
return JsonResponse({"ok": True, "billingInfo": billing_info, **structure_data})


@login_required
@group_required("Счет: проект")
def confirm_billing(request):
body = json.loads(request.body)
billing_id = body.get("billingId")
iss_ids = body.get("issIds")
price_id = body.get("priceId")
with transaction.atomic():
is_confirm_billing = BillingRegister.confirm_billing(billing_id)
set_billing_id_for_iss = Issledovaniya.save_billing(billing_id, iss_ids)
data_confirm_billing = get_confirm_data_for_billing(price_id, billing_id)
raw_document_pk = RawDocumentBillingRegister.create_raw_billing_data(billing_id, data_confirm_billing)

return JsonResponse({"ok": is_confirm_billing and set_billing_id_for_iss and raw_document_pk})


@login_required
@group_required("Счет: проект")
def change_visibility_research(request):
request_data = json.loads(request.body)
result = Researches.change_visibility(request_data["researchPk"])
return status_response(result)


@login_required
@group_required("Счет: проект")
def get_billings(request):
request_data = json.loads(request.body)
hospital_id = request_data.get("hospitalId")
company_id = request_data.get("companyId")
result = BillingRegister.get_billings(hospital_id, company_id)
return JsonResponse({"result": result})


@login_required
@group_required("Счет: проект")
def get_billing(request):
request_data = json.loads(request.body)
billing_id = request_data.get("billingId")
result = BillingRegister.get_billing(billing_id)
type_price = request_data.get("typeCompany")
data = researches_for_billing(type_price, result["hospitalId"], result["dateStart"], result["dateEnd"])
structure_data = structure_table(data)
return JsonResponse({"result": result, **structure_data})
1 change: 1 addition & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
path('health/', include('api.health.urls')),
path('chats/', include('api.chats.urls')),
path('ecp/', include('api.ecp.urls')),
path('contracts/', include('api.contracts.urls')),
path('transfer-document/', include('api.transfer_document.urls')),
path('edit-forms/', include('api.edit_forms.urls')),
path('hospitals/', include('api.hospitals.urls')),
Expand Down
7 changes: 6 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2926,12 +2926,17 @@ def delete_research_in_price(request):
@login_required
@group_required("Конструктор: Настройка организации")
def get_companies(request):
request_data = json.loads(request.body)
if request_data.get('selectedType') == 'Работодатель' or not request_data.get('selectedType'):
companies = Company.objects.filter(active_status=True).order_by("title")
else:
companies = Hospitals.objects.filter(hide=False).order_by('title')
company_data = [
{
"pk": company.pk,
"title": company.title,
}
for company in Company.objects.filter(active_status=True).order_by("title")
for company in companies
]
return JsonResponse({"data": company_data})

Expand Down
6 changes: 6 additions & 0 deletions context_processors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ def menu(request):
"nt": False,
"access": ["Обороты"],
},
{
"url": '/ui/billing',
"title": "Счета на оплату",
"nt": True,
"access": ["Счет: проект, Счет: закрытие"],
},
{"url": "/ui/utils", "title": "Инструменты", "nt": False, "access": ["Инструменты"]},
]

Expand Down
9 changes: 8 additions & 1 deletion contracts/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from .models import PriceName, PriceCoast, Contract, Company, PriceCategory, CompanyDepartment, MedicalExamination
from .models import PriceName, PriceCoast, Contract, Company, PriceCategory, CompanyDepartment, MedicalExamination, BillingRegister


class ResPriceCoast(admin.ModelAdmin):
Expand Down Expand Up @@ -94,10 +94,17 @@ class ResMedicalExamination(admin.ModelAdmin):
autocomplete_fields = ('card',)


class ResBillingRegister(admin.ModelAdmin):
list_display = ('company', 'hospital',)
list_display_links = ('company', 'hospital',)
list_filter = ('hospital', 'create_at',)


admin.site.register(PriceCategory)
admin.site.register(PriceName)
admin.site.register(Contract, ResContract)
admin.site.register(Company, ResCompany)
admin.site.register(CompanyDepartment, ResCompanyDepartment)
admin.site.register(PriceCoast, ResPriceCoast)
admin.site.register(MedicalExamination, ResMedicalExamination)
admin.site.register(BillingRegister, ResBillingRegister)
Loading

0 comments on commit fbc2fa0

Please sign in to comment.