Skip to content

Commit

Permalink
Merge pull request #3817 from mikhailprivalov/billing-info-fix
Browse files Browse the repository at this point in the history
Billing info fix
  • Loading branch information
urchinpro authored May 19, 2024
2 parents 19db020 + 9dbf345 commit 7821f9e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 61 deletions.
68 changes: 35 additions & 33 deletions api/contracts/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def researches_for_billing(type_price, company_id, date_start, date_end, price_i
hospital_id = company_id
base = CardBase.objects.filter(internal_type=True).first()
finsource = IstochnikiFinansirovaniya.objects.filter(base=base, title__in=["Договор"], hide=False).first()
if not finsource:
return {"ok": False, "result": [], "issIds": [], "priceId": "", "message": "Нет источника финансирования 'Договор'"}
if not is_confirmed:
sql_result = statistics_research_by_hospital_for_external_orders(date_start, date_end, hospital_id, finsource.pk, price_id)
else:
Expand All @@ -20,27 +22,26 @@ def researches_for_billing(type_price, company_id, date_start, date_end, price_i
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,
"execute_date": i.date_confirm,
"dir_id": i.dir_id,
}
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_id}
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,
"execute_date": i.date_confirm,
"dir_id": i.dir_id,
}
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 {"ok": True, "result": result, "issIds": list(iss_data), "priceId": price_id}


def get_confirm_data_for_billing(price_id, billing_id):
Expand Down Expand Up @@ -147,18 +148,19 @@ def structure_table(data_researches):
"executeDate": "",
"summ": sum_patient,
}
patient_data["total"] = {
"serialNumber": "",
"patientFio": "Итого",
"patientBirthDay": "",
"tubeNumber": "",
"coast": "",
"researchTitle": "",
"internalId": "",
"codeNMU": "",
"executeDate": "",
"summ": total,
}
if patient_data:
patient_data["total"] = {
"serialNumber": "",
"patientFio": "Итого",
"patientBirthDay": "",
"tubeNumber": "",
"coast": "",
"researchTitle": "",
"internalId": "",
"codeNMU": "",
"executeDate": "",
"summ": total,
}

table_data = [v for v in patient_data.values()]
return {"columns": columns, "tableData": table_data}
23 changes: 22 additions & 1 deletion api/contracts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from directions.models import Issledovaniya
from directory.models import Researches
from laboratory.decorators import group_required
from slog.models import Log
from utils.response import status_response


Expand Down Expand Up @@ -70,6 +71,15 @@ def confirm_billing(request):
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)
Log.log(
billing_data.pk,
200000,
request.user.doctorprofile,
{
"billing": {"pk": billing_data.pk, "date_from": str(billing_data.date_from), "registry_number": billing_data.registry_number},
"who_confirm": {"pk": user_who_create.pk, "family": user_who_create.family, "name": user_who_create.name, "patronymic": user_who_create.patronymic},
},
)
structure_data = structure_table(data)
return JsonResponse({"ok": is_confirm_billing and set_billing_id_for_iss and raw_document_pk, **structure_data})

Expand All @@ -87,6 +97,15 @@ def cancel_billing(request):
billing_data.who_create = user_who_create
billing_data.save()
Issledovaniya.cancel_billing(billing_id)
Log.log(
billing_data.pk,
200001,
request.user.doctorprofile,
{
"billing": {"pk": billing_data.pk, "date_from": str(billing_data.date_from), "registry_number": billing_data.registry_number},
"who_cancel": {"pk": user_who_create.pk, "family": user_who_create.family, "name": user_who_create.name, "patronymic": user_who_create.patronymic},
},
)
return JsonResponse({"ok": True})


Expand Down Expand Up @@ -131,5 +150,7 @@ def get_billing(request):
result = BillingRegister.get_billing(billing_id)
type_price = request_data.get("typeCompany")
data = researches_for_billing(type_price, result["hospitalId"], result["dateStart"], result["dateEnd"], result["priceId"], result["isConfirmed"], billing_id)
if not data["ok"]:
return JsonResponse({"ok": data["ok"], "result": [], "message": data["message"]})
structure_data = structure_table(data)
return JsonResponse({"result": result, **structure_data})
return JsonResponse({"ok": True, "result": result, "message": "", **structure_data})
6 changes: 3 additions & 3 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,19 +2682,19 @@ def update_price(request):
if request_data.get("typePrice") == "Работодатель":
current_price = PriceName(
title=request_data["title"], symbol_code=request_data["code"], date_start=request_data["start"], date_end=request_data["end"], company_id=request_data["company"],
contract_number=request_data["contractNumber"]
contract_number=request_data.get("contractNumber")
)
elif request_data.get("typePrice") == "Заказчик":
hospital = Hospitals.objects.filter(pk=int(request_data["company"])).first()
current_price = PriceName(
title=request_data["title"], symbol_code=request_data["code"], date_start=request_data["start"], date_end=request_data["end"], hospital=hospital, subcontract=True,
contract_number=request_data["contractNumber"]
contract_number=request_data.get("contractNumber")
)
elif request_data.get("typePrice") == "Внешний исполнитель":
hospital = Hospitals.objects.filter(pk=int(request_data["company"])).first()
current_price = PriceName(
title=request_data["title"], symbol_code=request_data["code"], date_start=request_data["start"], date_end=request_data["end"], hospital=hospital, external_performer=True,
contract_number=request_data["contractNumber"]
contract_number=request_data.get("contractNumber")
)
if current_price:
current_price.save()
Expand Down
10 changes: 6 additions & 4 deletions forms/xlsx/billing/billing_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ def fill_billing(ws1, data, row=14):
style_border2.border = Border(left=bd, top=bd, right=bd, bottom=bd)
style_border2.font = Font(bold=False, size=10)
style_border2.alignment = Alignment(wrap_text=True, horizontal="center", vertical="center")
logo = Image(os.path.join(BASE_DIR, "forms", "xlsx", "media", "logo.png"))
logo.height = 130
logo.width = 920
ws1.add_image(logo, "A1")
logo_exists = os.path.exists(f"{BASE_DIR}/forms/xlsx/media/logo.png")
if logo_exists:
logo = Image(os.path.join(BASE_DIR, "forms", "xlsx", "media", "logo.png"))
logo.height = 130
logo.width = 920
ws1.add_image(logo, "A1")
ws1.merge_cells("A9:L11")
megre_cell = ws1["A9"]
megre_cell.value = "Реестр № 1YYYY от 00 марта 2024 года \n оказанных медицинских услуг по договору №00 - 00/00/2024 \n с 00.00.00 по 00.00.00"
Expand Down
39 changes: 19 additions & 20 deletions l2-frontend/src/pages/Billing/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ const currentBillingData = ref({
registryNumber: '',
});
const datesFilled = computed(() => !!(currentBillingData.value.dateStart && currentBillingData.value.dateEnd));
const clearBilling = () => {
currentBillingData.value = { ...billingTemplate.value };
};
Expand All @@ -292,17 +293,21 @@ const getPrices = async () => {
const getBilling = async () => {
await store.dispatch(actions.INC_LOADING);
const { result, columns, tableData } = await api('contracts/get-billing', {
const {
ok, result, message, columns, tableData,
} = await api('contracts/get-billing', {
billingId: selectedBilling.value,
typeCompany: selectedType.value,
});
await store.dispatch(actions.DEC_LOADING);
currentBillingData.value = result;
colTable.value = columns;
services.value = tableData;
const { data } = await api('contracts/get-hospital-prices', { ...currentBillingData });
prices.value = data;
selectedPrice.value = result.priceId;
if (ok) {
currentBillingData.value = result;
colTable.value = columns;
services.value = tableData;
selectedPrice.value = result.priceId;
} else {
root.$emit('msg', 'error', message);
}
};
watch(selectedBilling, () => {
Expand Down Expand Up @@ -343,12 +348,12 @@ const confirmBilling = async () => {
const priceId = selectedPrice.value;
await store.dispatch(actions.INC_LOADING);
const {
ok, billingInfo,
ok,
} = await api(apiPoint, { ...billingData, priceId });
await store.dispatch(actions.DEC_LOADING);
if (ok) {
await getBilling();
root.$emit('msg', 'ok', `${billingInfo} сохранен`);
root.$emit('msg', 'ok', 'Счёт подтверждён');
} else {
root.$emit('msg', 'error', 'ошибка');
}
Expand All @@ -360,12 +365,12 @@ const cancelBilling = async () => {
const apiPoint = 'contracts/cancel-billing';
await store.dispatch(actions.INC_LOADING);
const {
ok, billingInfo,
ok,
} = await api(apiPoint, { id: selectedBilling.value });
await store.dispatch(actions.DEC_LOADING);
if (ok) {
await getBilling();
root.$emit('msg', 'ok', `${billingInfo} Отменен`);
root.$emit('msg', 'ok', 'Счёт сброшен');
} else {
root.$emit('msg', 'error', 'ошибка');
}
Expand All @@ -392,21 +397,16 @@ const createBilling = async () => {
await store.dispatch(actions.DEC_LOADING);
if (ok) {
root.$emit('msg', 'ok', 'Создано');
await getBillings();
selectedBilling.value = billingInfo;
} else {
root.$emit('msg', 'error', 'ошибка');
}
}
};
watch(() => currentBillingData.value.dateStart, (newValue, oldValue) => {
if ((newValue !== oldValue) && currentBillingData.value.dateEnd) {
getPrices();
}
});
watch(() => currentBillingData.value.dateEnd, (newValue, oldValue) => {
if ((newValue !== oldValue) && currentBillingData.value.dateStart) {
watch(() => [currentBillingData.value.dateStart, currentBillingData.value.dateEnd], () => {
if (datesFilled.value) {
getPrices();
}
});
Expand All @@ -415,7 +415,6 @@ watch(selectedCompany, () => {
if (selectedCompany.value) {
selectedBilling.value = null;
getBillings();
getPrices();
} else {
selectedBilling.value = null;
}
Expand Down
2 changes: 2 additions & 0 deletions slog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class Log(models.Model):
(190002, 'FTP HL7: результат pull'),
(190003, 'FTP HL7: результат push'),
(190004, 'REST: заказ принятие'),
(200000, 'Счет на оплату: подтверждение'),
(200001, 'Счет на оплату: сброс подтверждения'),
)

# Виды событий, которые могут быть очищены
Expand Down

0 comments on commit 7821f9e

Please sign in to comment.