-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3782 from mikhailprivalov/accountRegister
Account register
- Loading branch information
Showing
18 changed files
with
786 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.